#K68987. Two Sum Problem
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:
- The first line contains an integer ( n ), denoting the number of elements in the array.
- The second line contains ( n ) space-separated integers representing the array.
- 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