01
Overview

Tracking streaks during a traversal.

Two counters — current streak, best streak — capture any "consecutive success" pattern.

A streak is a run of consecutive elements (or events) that all satisfy some condition. Streak logic powers attendance tracking, quiz performance, hot streaks in games, and any "longest consecutive X" question.

The pattern: track a current streak that grows when the condition continues and resets when it breaks. A separate variable holds the best streak ever seen.

On the AP exam, streak logic appears in array problems and in object-list problems alike — anywhere "consecutive" or "in a row" appears in the prompt.

02
Core Concept

Increment on success; reset on failure; track the best.

Three operations cover every streak problem.

The template

int current = 0;
int best = 0;
for (int x : data) {
    if (condition(x)) {
        current++;
        if (current > best) best = current;
    } else {
        current = 0;
    }
}
return best;

Concrete example: longest passing streak

public int longestPassingStreak(int[] scores) {
    int current = 0, best = 0;
    for (int s : scores) {
        if (s >= 60) {
            current++;
            if (current > best) best = current;
        } else {
            current = 0;
        }
    }
    return best;
}

Updating best — inside the match branch only

The reset branch can never produce a new maximum, so updating best there is wasted code. Keep the update tightly bound to the success path.

Initial values

For "consecutive matches", both current and best start at 0 — a single match makes them 1.

03
Key Vocabulary

Streak vocabulary.

Used in consecutive-success problems.

Vocabulary
  • Streak — a consecutive sequence of successes.
  • Current streak — counter tracking the active run.
  • Best streak — running maximum across all streaks seen.
  • Reset — return current to 0 on a break.
  • Match branch — code path when the condition holds.
  • Break branch — code path when the condition fails.
04
AP Exam Focus

How streak logic is tested.

Initialization and where best updates dominate.

Exam Focus
  • Update best inside the success branch. The reset branch can't beat best.
  • Reset to 0, not -1. The next success will produce 1.
  • One pass. Streak logic is always single-pass.
  • Both counters initialize to 0. Handles empty input gracefully.
05
Worked Example

Longest passing streak.

Trace both counters every step.

Worked Example AP-style reasoning

Input: [55, 70, 80, 40, 90, 85, 60, 30] with passing = 60.

Trace.

  • 55 (fail): current=0, best=0.
  • 70: current=1, best=1.
  • 80: current=2, best=2.
  • 40 (fail): current=0.
  • 90: current=1.
  • 85: current=2.
  • 60: current=3, best=3.
  • 30 (fail): current=0.

Answer: 3.

06
Common Mistakes

Streak pitfalls.

Most miss the best-update or reset incorrectly.

Watch Out
  • Updating best after the loop only. Misses streaks that don't reach the end.
  • Resetting to 1 instead of 0. Off-by-one — the next match would jump to 2.
  • Comparing wrong direction. Use current > best for strict improvement.
  • Forgetting to reset. Streak runs through breaks.
07
Reference Table

Streak operations.

Three actions, two counters.

Streak Reference

AP Quick Reference
ActionWhenEffect
Increment currentMatchcurrent++
Update bestMatch, if exceedsbest = current
Reset currentBreakcurrent = 0
Initial valuesBefore loopBoth 0
08
Practice Tip

How to master streak logic.

Trace both counters; never update best in reset.

Practice Strategy
  • MCQ Practice — write current and best after each element.
  • Java Lab — implement longestPassing, longestPositive, longestCorrect. Vary the match condition.
  • FRQ Practice — when "consecutive" or "in a row" appears, reach for this template.
09
Section · 09

Practice — attempt these now.

AP-style assessments aligned to this lesson. Time them.

FRQ Practice 30 min 18 marks Pending

AP CSA Unit 09 Topic 01 Consecutive-Run (Streak) Logic FRQ Practice

AP-style topic practice assessment

Start