#K82042. Two Sum Problem
Two Sum Problem
Two Sum Problem
Given an array of integers \(A\) of size \(n\) and an integer target \(T\), find two distinct indices \(i\) and \(j\) (0-indexed) such that \(A[i] + A[j] = T\). If such a pair exists, output the two indices separated by a space; otherwise, output \(-1 -1\).
Note: There will be at most one valid pair for each input. You are allowed to return any valid answer.
inputFormat
The input is given from stdin and consists of three lines:
- The first line contains an integer \(n\) representing the number of elements in the array.
- The second line contains \(n\) space-separated integers representing the elements of the array \(A\).
- The third line contains an integer \(T\), the target sum.
outputFormat
Output to stdout two space-separated integers representing the indices \(i\) and \(j\) such that \(A[i] + A[j] = T\). If no such pair exists, output -1 -1
.
4
2 7 11 15
9
0 1