Algorithms and Data Structures · Junior · Question 42 of 75

What is the "two pointers" technique?

Explanation

Two indices move through the array instead of nested loops, which often turns O(n²) into O(n). Classic uses: checking a palindrome from both ends, merging two sorted arrays, finding a pair with a given sum in a sorted array.

Further reading

Problem with a question

Algorithms and Data Structures · Junior · question 42

Test yourself

Take the Algorithms and Data Structures · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz