Find a lesson, question or project

Start typing to search published content and planned structures.

↑ ↓ moveEnter openEsc close
01 / WHAT IT SOLVES

Membership, frequency and earliest-position questions where repeated searching is the bottleneck.

02 / HOW TO RECOGNIZE IT
  • have we seen this before
  • count occurrences
  • find a matching earlier state
03 / PROTECT THIS INVARIANT

The map contains exactly the historical facts needed to answer the current step.

04 / EXPECTED COST

Usually O(n) expected time. Typical auxiliary space: Usually O(n).

JAVA STARTING POINT

A template to adapt, not memorize.

Java
Map<Integer, Integer> firstIndex = new HashMap<>();
for (int index = 0; index < values.length; index++) {
    firstIndex.putIfAbsent(values[index], index);
}

Common mistakes

  • Overwriting the earliest index
  • Assuming worst-case O(1) lookup
  • Using a map when a small fixed array is clearer

PUBLISHED / 06

Learn in this order.

Available articles always appear before the publishing plan.

PLANNED PRACTICE

What comes after the published lessons.

  1. Two sumPlanned, not yet published
  2. Subarray sum equals kPlanned, not yet published