#K41257. Two Sum Problem
Two Sum Problem
Two Sum Problem
Given an array of integers, your task is to find two distinct numbers whose sum equals a given target value. Return the indices of these two numbers as a pair, where the indices are zero-based. If no such pair exists, output nothing.
The problem can be mathematically stated as follows: Given an array (A = [a_0, a_1, \dots, a_{n-1}]) and a target integer (T), find indices (i, j) such that (a_i + a_j = T).
inputFormat
The input consists of three lines:
- The first line contains an integer (n), representing the number of elements in the list.
- The second line contains (n) space-separated integers.
- The third line contains a single integer representing the target value.
outputFormat
If a valid pair exists, output the two indices separated by a space. If multiple solutions exist, output the first valid pair found. If no valid pair exists, output nothing.## sample
4
2 7 11 15
9
0 1
</p>