Using the Two Pointer Technique

Jake Zhang
The Startup
Published in
5 min readAug 15, 2020

--

The Two Pointer Technique

The two-pointer technique is a near necessity in any software developer’s toolkit, especially when it comes to technical interviews. In this guide, we’ll cover the basics so that you know when and how to use this technique.

This lesson was originally published at https://algodaily.com, where I maintain a technical interview course and write think-pieces for ambitious developers.

What is the pattern?

The name two pointers does justice in this case, as it is exactly as it sounds. It's the use of two different pointers (usually to keep track of array or string indices) to solve a problem involving said indices with the benefit of saving time and space. See the below for the two pointers highlighted in yellow.

But what are pointers? In computer science, a pointer is a reference to an object. In many programming languages, that object stores a memory address of another value located in computer memory, or in some cases, that of memory-mapped computer hardware.

When do we use it?

--

--