Sitemap
MyCodeBook

MyCodeBook

A Passionate Coder and Aspiring Entrepreneur

Two Pointer Method

Dec 29, 2025

The two pointers method uses two indices(pointers) to traverse through a data structure(mainly arrays or strings) efficiently.

It is used to reduce the Time and space complexities of problems.
If brute force method uses O(n²) time complexity, two pointers method solves it in O(n).

There are 3 variations :

Get MyCodeBook’s stories in your inbox

Join Medium for free to get updates from this writer.

1. Converging Pointers
2. Parallel Pointers( Sliding Window)
3. Trigger-based Pointers

Now let’s dive into Converging pointers :

This approach uses two pointers:
left → starts from the beginning
right → starts from the end
How it works:
Check the condition using left and right
1. If the condition is satisfied → return the result
2. If the value is less than required → increment the left pointer
3. If the value is greater than required → decrement the right pointer

Pseudocode
Press enter or click to view image in full size
Two Pointer Approach (AI)

--

--

MyCodeBook
MyCodeBook

Written by MyCodeBook

0 followers

A Passionate Coder and Aspiring Entrepreneur