#C12461. Two Sum Indices

    ID: 41891 Type: Default 1000ms 256MiB

Two Sum Indices

Two Sum Indices

Given an array of integers and a target integer \(T\), find two distinct indices \(i\) and \(j\) such that:

\(nums[i] + nums[j] = T\)

If such a pair exists, output the two indices (0-based) separated by a space. Otherwise, output "No two numbers add up to the target".

Note: Each input will have at most one solution. You may not use the same element twice.

inputFormat

The input is given via standard input (stdin) in the following format:

  • 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 array elements.
  • The third line contains an integer \(T\), the target sum.

outputFormat

Output via standard output (stdout) should be:

  • If a valid pair exists, output two space-separated integers corresponding to their indices.
  • If no such pair exists, output: "No two numbers add up to the target"
## sample
4
2 7 11 15
9
0 1