Using Two-Pointer Technique to Optimize Algorithm Solutions

Annie Liao
Level Up Coding
Published in
3 min readSep 26, 2020

--

Photo by Max Duzij on Unsplash

When dealing with strings and arrays in the context of algorithm challenges, our first instinct usually revolves around built-in methods.

Let’s take a look at this seemingly easy problem:

/* Description:
Given a sorted (ascending) array of integers,
write a function that returns a sorted (ascending) array
which contains the square of

--

--

Fullstack Developer: React with Rails. Currently exploring data structures, D3 visualization, and other front-end magic.