#K58472. Find a Pair With a Given Sum
Find a Pair With a Given Sum
Find a Pair With a Given Sum
You are given an array of integers and a target sum. Your task is to determine if there exists any pair of distinct numbers in the array whose sum is exactly equal to the target. Use an efficient algorithm to solve this problem. For example, in the array [1, 2, 4, 4] with target 8, the pair (4,4) gives the desired sum. If such a pair exists, print True
; otherwise, print False
.
inputFormat
The first line of input contains two space-separated integers: n (the number of elements in the array) and target (the required sum). The second line contains n space-separated integers representing the array elements. Note that when n is 0, the second line may be empty.
outputFormat
Output a single word: True
if there exists at least one pair of numbers in the array that adds up to target, otherwise False
.## sample
4 8
1 2 3 9
False