Arrays and Strings

Overview

Arrays come in many varieties. But for the purposes of this section, we’re talking about any ordered collection of elements whose elements can be accessed by index. Strings fit this definition. The techniques here are different methods for iterating over the elements efficiently to solve problems.

Two Pointers

Problem: Three Sum

The two pointers technique uses two pointers that either start at different places or move in different directions or at different speeds in order to find a solution. (A pointer is a reference to an element in an array.)

function myFunction(): number {
  return 0;
}

Sliding Window

Problem: Longest Substring Without Repeating Characters

function myFunction(): number {
  return 0;
}

Problem: Search in a Rotated Sorted Array

function myFunction(): number {
  return 0;
}

Prefix Sum

Problem: Maximum Subarray

function myFunction(): number {
  return 0;
}