Two Pointers
1 / 5

Two Pointers

Use two pointers to solve array problems

code
let left = 0, right = arr.length - 1;
while (left < right) {
  // process
}
Sliding Window
2 / 5

Sliding Window

Track a window of elements

code
for (let i = 0; i < arr.length; i++) {
  window.push(arr[i]);
  if (window.length > k) window.shift();
}
Binary Search
3 / 5

Binary Search

Efficiently search sorted arrays

code
while (left <= right) {
  let mid = Math.floor((left + right) / 2);
  if (arr[mid] === target) return mid;
}
Recursion
4 / 5

Recursion

Solve problems by breaking them down

code
function factorial(n) {
  if (n <= 1) return 1;
  return n * factorial(n - 1);
}