Input/Output in Leetcode

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

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.

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

3 Likes

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

1 Like

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 : http://p.ip.fi/qxhL ,Finally submitted it using vector.

1 Like

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 for it [Problem statement is present in the code] .