#C8023. Two Sum Problem
Two Sum Problem
Two Sum Problem
Given an array of integers and a target integer \(T\), find two distinct indices \(i\) and \(j\) such that \(array[i] + array[j] = T\). If a valid pair exists, print the two indices separated by a space. Otherwise, print []
to indicate that no solution exists.
Note: The input is provided via standard input, and exactly one valid pair is expected if a solution exists.
inputFormat
The input consists of two lines read from stdin:
- The first line contains space-separated integers representing the array.
- The second line contains a single integer representing the target sum \(T\).
outputFormat
If a valid pair exists, output the two 0-indexed indices separated by a space using stdout. Otherwise, output []
.
2 7 11 15
9
0 1