Two Sum
Practice this coding question on Coding Gurukul.
Problem statement
A dispatch desk records package weights in arrival order. Choose two different packages whose combined weight matches the requested load. The input guarantees exactly one valid pair. Report their zero-based positions in increasing order; a package cannot be selected twice.
Input format
First line: n target. Second line: n integer weights.
Output format
Print the two zero-based indices, smaller first.
Constraints
2 <= n <= 100000; -1000000000 <= weights, target <= 1000000000; exactly one pair exists.
Sample input
4 13 8 4 9 2
Sample output
1 2
Sign in to run or submit a solution in C++, Java or Python.