Given an array arr of positive integers and another number target. Determine whether two elements exist in arr whose sum is exactly target or not. Return true if two elements exist in the arr else return false.
Examples
Example 1
Example 1
Input: arr[] = [1, 4, 9, 6, 10, 8], target =16
Output: true
Explanation: arr[3] + arr[4] = 6 + 10 = 16
Example 2
Example 2
Input: arr[] = [1, 2, 4, 3, 6], target = 11
Output: false
Explanation: None of the pair makes a sum of 11
Hints
Hint 1
Expected Time Complexity O(n)
Hint 2
Expected Space Complexity O(n)
Constraints
1 <= arr.size <= 10^5
1 <= arr[i] <= 10^5
Companies
AmazonMicrosoftAdobeGoogleTCS+ 5 more
Topics
ArrayHashingHashmap
Track your submissions
Please log in to review your progress and explore code submissions from other participants.
Unlock the full solution
Please log in to access detailed answers and explanations.
Join the discussion
Please log in to join conversations with other participants.
Solution.csC#JavaPythonC++Javascript
1
2
3
4
5
6
7
8
9
10
Unlock the code editor
Sign in to write, run, and submit your solution against the full test suite.