0% completed
Introduction to Two Pointers Pattern
You are given a sorted array and a target sum. Find two numbers that add up to the target.
[1, 3, 4, 6, 8, 11] target = 10
A simple solution checks every possible pair. For each number, compare it with every number after it.
This solution uses two nested loops. Its time complexity is O(N²), where N is the number of values.
However, this solution ignores one important fact: the array is sorted.
Start with the smallest value, 1, and the largest value, 11. Their sum is 12, which is greater than 10.
Because 1 is the smallest value, every other pair that contains
.....
.....
.....
Puneeth
· 2 months ago
Two pointers technique is useful whenever we have a set of elements let's say a pair, a triplet or even a subarray given we have a sorted array and we have to fulfil certain constraints.
Hajin Kim
· 2 years ago
It would be awesome if I could just write up notes on the side of each material so I can refer back to it
surbhi
· 4 years ago
Hello, Are there any patterns for solving String related questions?
Mohammad Awad
· 4 years ago
hi
Reading Progress
0%