Skip to main content

← Arrays

Two sum

easy

The first line has n and a target. The second line has n integers. Print the 0-based positions i < j of the two numbers that add up to the target, separated by a space. There is exactly one answer.

Example 1: input

4 9
2 7 11 15

Output

0 1

Example 2: input

3 6
3 2 4

Output

1 2

Plus 2 hidden tests when you check your answer.

Your solution

Read from standard input and print the answer. Run it on the examples as often as you like, then check it against every test.

Stuck?

Open hints one at a time. The write-up explains a full solution.

Discussion

Ask a question or share a tip. Please don’t post full solutions. Posts appear once a moderator approves them.

No posts yet.