Find a lesson, question or project

Start typing to search published content and planned structures.

↑ ↓ moveEnter openEsc close
01 / WHAT IT SOLVES

Questions that ask you to inspect, validate, count or summarize an entire array.

02 / HOW TO RECOGNIZE IT
  • every element matters
  • one pass is possible
  • the answer can be updated while scanning
03 / PROTECT THIS INVARIANT

After index i, the stored state correctly describes the processed prefix from 0 through i.

04 / EXPECTED COST

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

JAVA STARTING POINT

A template to adapt, not memorize.

Java
for (int index = 0; index < values.length; index++) {
    int value = values[index];
    // Update the answer using value.
}

Common mistakes

  • Starting from an unsafe default value
  • Skipping the first or last index
  • Forgetting empty-input behavior

PUBLISHED / 06

Learn in this order.

Available articles always appear before the publishing plan.

PLANNED PRACTICE

What comes after the published lessons.

  1. Count elements matching a conditionPlanned, not yet published
  2. Maximum consecutive onesPlanned, not yet published