Two Sum with Sorted Array

Subscribers:
50,600
Published on ● Video Link: https://www.youtube.com/watch?v=d7lQwuPu23g



Duration: 9:21
136 views
2


Given a sorted array of integers and a target integer number, if there are two distinct numbers in the sorted list that can add up to the target, return true otherwise, false. This problem is similar to leetcode 167 two sum II input array is sorted.

https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/

In this video, we started off with a brute force solution by checking every single pair combination. This is considered brute force because there is work being done that isn't necessary. This solution would be O(N^2).

Instead, we can use the two pointer technique to traverse through the list in a single loop for a runtime of O(N). One variable keeps track of the left index (smallest number) while the another keeps track of the right index (largest number). If the sum of the number at these indices is too small, move left up, if too big, move right down.

Python Playlist:
https://youtube.com/playlist?list=PLnKe36F30Y4bcRomKi02sP9NR27KnBqCK

Github: https://github.com/ImKennyYip/python-data-structures-algorithms

Subscribe for more coding tutorials 😄!







Tags:
two sum II
two sum II leetcode
two sum sorted array
two sum array is sorted
two sum list is sorted
two sum sorted list
two sum II array is sorted
two sum II leetcode sorted array
2 sum sorted array
2 sum sorted list
2 sum array is sorted
2 sum II
2 sum II sorted list
two sum II list is sorted
two sum II array sorted
sorted array two sum
sorted list two sum
sorted array two sum II
two sum II leetcode 167
two sum II sorted array leetcode 167
leetcode 167