#C13655. Two Sum Problem

    ID: 43217 Type: Default 1000ms 256MiB

Two Sum Problem

Two Sum Problem

Given an array of integers nums and an integer target, find the indices of the two numbers such that they add up to the target. More formally, find indices i and j (with i < j) satisfying the equation $$nums[i] + nums[j] = target.$$ If there is no such pair, output -1.

You may assume that each input would have at most one solution. The answer must be returned as two indices separated by a space in the order they appear in the array. This is a classic problem that tests your ability to use data structures such as hash maps for an efficient solution.

inputFormat

The input is read from standard input (stdin) and consists of three lines:

  1. The first line contains an integer n representing the number of elements in nums.
  2. The second line contains n space-separated integers representing the array nums.
  3. The third line contains a single integer target.

outputFormat

Output to standard output (stdout) the indices of the two numbers that add up to target, separated by a space. If no such pair exists, output -1.

## sample
4
2 7 11 15
9
0 1