# Input/Output in Leetcode

**URL:** <https://discuss.codechef.com/t/input-output-in-leetcode/55147>\
**Category:** help\
**Tags:** leetcode\
**Created:** [March 2, 2020, 7:27pm UTC](https://discuss.codechef.com/t/input-output-in-leetcode/55147 "2020-03-02T19:27:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shahil\_005](https://discuss.codechef.com/user_avatar/discuss.codechef.com/shahil_005/32/148185_2.png) [@shahil\_005](https://discuss.codechef.com/u/shahil_005)\
**Post date:** [March 2, 2020, 7:27pm UTC](https://discuss.codechef.com/t/input-output-in-leetcode/55147/1 "2020-03-02T19:27:38Z")

</div>

Can someone tell me how to take input and give output in leetcode problems.  
Like for eg : [- LeetCode](https://leetcode.com/problems/two-sum/)

[pastebin](http://p.ip.fi/Mfk0) - This is my solution,but I don’t know to take input the way it is given in the question.Also,the output method is different.

---

<div class="post-metadata">

**Author:** ![anon70990627](https://www.codechef.com/sites/all/themes/abessive/images/user_default_thumb.jpg) [@anon70990627](https://discuss.codechef.com/u/anon70990627)\
**Post date:** [March 2, 2020, 8:26pm UTC](https://discuss.codechef.com/t/input-output-in-leetcode/55147/2 "2020-03-02T20:26:01Z")

</div>

In leetcode, a function is given where the input is already taken. You just have to write the logic inside the function and return the required output

---

<div class="post-metadata">

**Author:** ![hello\_hell](https://discuss.codechef.com/user_avatar/discuss.codechef.com/hello_hell/32/53660_2.png) [@hello\_hell](https://discuss.codechef.com/u/hello_hell)\
**Post date:** [March 2, 2020, 8:59pm UTC](https://discuss.codechef.com/t/input-output-in-leetcode/55147/3 "2020-03-02T20:59:08Z")

</div>

you already have your input in vector “nums” and integer “target”. Just implement your logic and you are good to go. 🙂

---

<div class="post-metadata">

**Author:** ![shahil\_005](https://discuss.codechef.com/user_avatar/discuss.codechef.com/shahil_005/32/148185_2.png) [@shahil\_005](https://discuss.codechef.com/u/shahil_005)\
**Post date:** [March 2, 2020, 9:17pm UTC](https://discuss.codechef.com/t/input-output-in-leetcode/55147/4 "2020-03-02T21:17:13Z")

</div>

[http://p.ip.fi/3C3i](http://p.ip.fi/3C3i)

Done exactly what you said,still having problem in returning 2 values i &j.  
Would be great help if someone just write the returning statement,else everything is fine i guess.

Edit : [pastebin](http://p.ip.fi/qxhL) ,Finally submitted it using vector.

---

<div class="post-metadata">

**Author:** ![hello\_hell](https://discuss.codechef.com/user_avatar/discuss.codechef.com/hello_hell/32/53660_2.png) [@hello\_hell](https://discuss.codechef.com/u/hello_hell)\
**Post date:** [March 3, 2020, 10:38am UTC](https://discuss.codechef.com/t/input-output-in-leetcode/55147/5 "2020-03-03T10:38:11Z")

</div>

That’s nice; what else you could have done is : map each number with it’s index then for each element in vector search for the `target-v[i]` element in the map. If found then return `{ mp[v[i]] , mp[target-v[i]]}` , and as it is mentioned that there will be always a solution exist.

I have seen similar problem in Daily Coding Problem and this is [my solution](https://github.com/offamitkumar/Daily-Coding-Problem/blob/master/Problem%23001.cpp) for it [Problem statement is present in the code] .
