Interview Bootcamp
Vote

0% completed

Introduction to Two Pointers Pattern

You are given a sorted array of numbers and a target sum. Find two numbers in the array that add up to that target.

[1, 3, 4, 6, 8, 11]     target = 10

The first approach most people try is to check every pair. Take the first number and compare it against every number after it. Then take the second number and do the same. With N numbers that is about N²/2 comparisons. For an array of 10,000 numbers, that is 50 million comparisons.

Now look at the array again. It is sorted, and the approach above never uses that fact.

.....

.....

.....

Like the course? Get enrolled and start learning!
Hajin Kim

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

S

surbhi

· 4 years ago

Hello, Are there any patterns for solving String related questions?

Show 2 replies
M

Mohammad Awad

· 4 years ago

hi

Show 1 reply
Puneeth

Puneeth

· a month 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.