Back to Browse

Check if pair with given Sum exists in Array (Two Sum)

152 views
Feb 24, 2024
10:36

Check if pair with given Sum exists in Array (Two Sum) Input: arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}, targetSum= 10 Output: Yes 1.Brute force approach using nested loops Time Complexity: O(n^2) Space Complexity: O(1) 2.Using sorting and two pointers approach Time Complexity: O(n log n) Space Complexity: O(1) 3.Efficient approach using hash table Time Complexity: O(n) Space Complexity: O(n)

Download

0 formats

No download links available.

Check if pair with given Sum exists in Array (Two Sum) | NatokHD