#C10288. Pair Sum Problem
Pair Sum Problem
Pair Sum Problem
Given an array of integers and an integer ( k ), determine whether there exist two distinct indices ( i ) and ( j ) such that ( a_i + a_j = k ). In other words, check if any pair of numbers from the array sums up to ( k ). This is a common problem that tests your ability to use efficient data structures for lookup.
Example: For the array [2, 7, 11, 15] and ( k=9 ), the pair (2, 7) satisfies the condition since ( 2+7=9 ), so the output should be True.
inputFormat
The first line contains an integer ( n ) representing the number of elements in the array. The second line contains ( n ) space-separated integers. The third line contains an integer ( k ), the target sum.
outputFormat
Output a single line: 'True' if there exists a pair of distinct elements in the array which sum to ( k ), otherwise 'False'.## sample
4
2 7 11 15
9
True