AP CSA FRQ Guide

2023 FRQ 3: WeatherData

Write two methods for analyzing daily high temperatures. The first removes values outside an inclusive valid range while preserving order. The second finds the length of the longest streak of temperatures above a threshold.

ArrayList Filtering and Streaks22 minute targetArrayListremovetraversalthresholdsconsecutive counts

Skills Tested

What this FRQ is really practicing

ArrayListremovetraversalthresholdsconsecutive counts

Treat these skills as the study checklist. If any tag feels shaky, review that topic before attempting the full written response.

Starter Approach

How to begin without copying a solution

  1. 1Part A: remove every temperature less than lower or greater than upper.
  2. 2Keep all values from lower through upper, inclusive, and preserve the order of remaining values.
  3. 3Part B: count consecutive temperatures greater than threshold.
  4. 4Return the maximum length of any heat wave streak.

Write a first attempt before revealing any solution outline. Most AP CSA FRQ progress comes from tracing your own code and finding the missing case.

Common Mistakes

Mistakes to watch for while writing

Removing while traversing forward and skipping the element that shifts into the removed position.
Removing values equal to lower or upper even though the bounds are inclusive.
Using >= threshold instead of > threshold for heat-wave days.
Returning the last streak instead of the longest streak.
Counting total hot days instead of consecutive hot days.

Self Check

Review questions before you submit

Defines cleanData with void return type and lower/upper parameters.

Part A modifies the temperatures list directly.

Traverses the temperatures ArrayList.

Use temperatures.size() and temperatures.get(index), or an equivalent traversal.

Removes values lower than lower or greater than upper.

The invalid condition uses < lower OR > upper.

Removes safely without skipping elements.

Traverse backward, or only increment after keeping an element.

Defines longestHeatWave with int return type and a threshold parameter.

Part B returns the length of the longest streak.

Checks for temperatures greater than threshold.

A heat wave day must be strictly greater than threshold.

Tracks the current consecutive heat-wave length.

Increment a current counter for heat-wave days.

Resets the current streak when a temperature does not qualify.

A non-heat-wave day breaks the consecutive sequence.

Practice Links

Where to go next