#K54697. Two Sum Problem

    ID: 29811 Type: Default 1000ms 256MiB

Two Sum Problem

Two Sum Problem

Given an array of integers and a target integer, your task is to find two distinct indices i and j in the array such that the following equation holds:

$$nums[i] + nums[j] = target$$

If such a pair exists, output the two indices (0-indexed) separated by a space; otherwise, output -1 -1. Note that if multiple solutions exist, any valid pair is acceptable.

inputFormat

The input is given via stdin and has the following format:

  • The first line contains an integer n, 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 target, the target sum.

outputFormat

Output to stdout a single line with two space-separated integers representing the indices of the two array elements that add up to target. If no such pair exists, output -1 -1.

## sample
4
2 7 11 15
9
0 1

</p>