#K56742. Two Sum: Find Indices of Two Numbers
Two Sum: Find Indices of Two Numbers
Two Sum: Find Indices of Two Numbers
You are given an array of integers and an integer target. Your task is to find two distinct indices in the array such that the sum of the numbers at these indices is equal to the target. If there are multiple valid solutions, return the first pair encountered.
Note that each input is guaranteed to have exactly one solution and you may not use the same element twice. The indices in the output are zero-based.
The problem can be mathematically formulated as follows: Given an array \(A = [a_0, a_1, \dots, a_{n-1}]\) and an integer \(T\), find \(i, j\) with \(0 \leq i, j < n,\ i \neq j\) such that \(a_i + a_j = T\).
inputFormat
The input is read from stdin and consists of two lines. The first line contains two integers separated by a space: \(n\), the number of elements in the array, and \(T\), the target value. The second line contains \(n\) space-separated integers representing the elements of the array.
Example:
4 9 2 7 11 15
outputFormat
The output is written to stdout and consists of two space-separated integers representing the indices of the two numbers that add up to the target.
Example:
0 1## sample
4 9
2 7 11 15
0 1