twoPointers
Problem
Solution
Steps
Sort the array.
Initialize two pointers, one from very left and another from very right.
Iterate through the array with while loop, increment left pointer when the sum is less than target, decrement right pointer when the sum is greater than target.
Time Complexity
Sorting is the biggest expense. It would be O(n log n)
at best worst case.
Iterating through a sorted array with two pointers is O(n)
time complexity.