#K62952. Two Sum Problem

    ID: 31645 Type: Default 1000ms 256MiB

Two Sum Problem

Two Sum Problem

You are given an array of integers A and an integer target T. Your task is to find two distinct indices i and j (with i < j) such that:

[ a_i + a_j = T ]

If such a pair exists, output the indices in the order they are found. If no such pair exists, output an empty list in the form []. This problem can be solved in \(O(n)\) time using a hash map.

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains a single integer \(n\) representing the number of elements in the array \(A\).
  • The second line contains \(n\) space-separated integers, which are the elements of \(A\).
  • The third line contains an integer \(T\), the target sum.

outputFormat

Output to standard output (stdout) a single line:

  • If a valid pair of indices \((i, j)\) exists such that \(a_i + a_j = T\), print the indices separated by a space.
  • If no such pair exists, print [] (without quotes).
## sample
4
2 7 11 15
9
0 1