Array - 16: Check if there exists a pair which matches given Sum
Code: https://thecodingsimplified.com/check-if-there-exists-a-pair-which-matches-given-sum/ Solution: Brute Force: - In this, each element will add to other element in array & check if target sum matches - Take two loop & add each element with every other & check the target sum. - Complexity: O(n^2) Sorting: - Sort the array - Take two variable, one from start & other from end. - If a[start] + a[end] = target_sum, it means there exists a sum - If target_sum is greater than a[start] + a[end], then decrease end, else increase start. - Complexity: O(nlog(n)) Hashing: - Take one Set & iterate each element of array - If target_sum - arr[i] is in set, we got the solution, else keep adding element in array. Please check video for more info: This problem is similar to: array check there is a pair for given sum, array check if pair exists for sum, array if sum adds ti two values, pair, sum, array, java tutorial, coding simplified, java CHECK OUT CODING SIMPLIFIED https://www.youtube.com/codingsimplified ★☆★ VIEW THE BLOG POST: ★☆★ http://thecodingsimplified.com I started my YouTube channel, Coding Simplified, during Dec of 2015. Since then, I've published over 400+ videos. ★☆★ SUBSCRIBE TO ME ON YOUTUBE: ★☆★ https://www.youtube.com/codingsimplified?sub_confirmation=1 ★☆★ Send us mail at: ★☆★ Email: [email protected]
Download
0 formatsNo download links available.