AP CSA FRQ Guide
2009 FRQ 1: NumberCube
Record number-cube tosses in an array and return the starting index of a longest run of consecutive equal values. Return -1 when no run has length two or greater.
Arrays and Consecutive Runs22 minute targetarraysobjectsloopsconsecutive runsindexes
Skills Tested
What this FRQ is really practicing
arraysobjectsloopsconsecutive runsindexes
Review these topics before attempting the problem.
Starter Approach
How to begin with your own plan
- 1Part A: allocate an array of numTosses values and fill it by calling cube.toss once for each entry.
- 2Part B: find the starting index of a longest run of at least two consecutive equal values; any tied longest run is acceptable.
- 3Return -1 when there is no run, including a one-element array.
Attempt the problem before opening the solution.
Common Mistakes
Mistakes to watch for while writing
Returning the run length instead of its starting index.
Counting equal values that are not consecutive.
Missing a run that reaches the final array element.
Self Check
Review questions before you submit
Allocates an integer array for all requested tosses.
The returned array must have numTosses entries.
Uses the supplied number cube to generate tosses.
Call cube.toss rather than generating unrelated random values.
Tracks run lengths and starting indexes.
Return a position in values, rather than the repeated value or run length.
Provides a -1 result when no run exists.
A run requires at least two consecutive equal values.
Practice Links
