#K68987. Two Sum Problem

    ID: 32986 Type: Default 1000ms 256MiB

Two Sum Problem

Two Sum Problem

Given an array of integers and an integer ( k ), determine if there exist two distinct indices ( i ) and ( j ) such that [ nums[i] + nums[j] = k ] Return 'True' if such a pair exists, otherwise return 'False'. This problem is a classic case of the Two Sum problem and can be solved efficiently using a hash set.

inputFormat

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

  1. The first line contains an integer ( n ), denoting the number of elements in the array.
  2. The second line contains ( n ) space-separated integers representing the array.
  3. The third line contains an integer ( k ), the target sum.

outputFormat

Output to standard output (stdout) a single line containing 'True' (without quotes) if there exists a pair of distinct elements whose sum equals ( k ), otherwise output 'False'.## sample

4
1 2 3 4
5
True