AP CSA FRQ Guide
2023 FRQ 4: BoxOfCandy
Write two methods for a rectangular candy box. The first moves a candy upward into the first row of a specified column when possible. The second searches from the bottom row upward for the next candy of a requested flavor, removes it, and returns it.
Skills Tested
What this FRQ is really practicing
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
- 1Part A: if row 0 already has candy in the column, leave the box unchanged and return true.
- 2If row 0 is empty, search lower rows in the same column for a candy to move into row 0.
- 3Set the moved candy old location to null and return true; return false if the column has no candy.
- 4Part B: search from the last row to the first row, left to right within each row, for the requested flavor.
- 5Remove and return the first matching Candy object, or return null when no match exists.
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
Self Check
Review questions before you submit
Defines moveCandyToFirstRow with boolean return type and a column parameter.
Part A reports whether a candy exists in the requested column.
Checks whether row 0 already contains candy in the column.
If box[0][col] is not null, return true without moving anything.
Searches rows below row 0 in the same column.
Loop from row 1 through the last row.
Moves a found candy to row 0.
Assign the found Candy reference to box[0][col].
Sets the moved candy old location to null.
After moving the reference, clear the original cell.
Returns true when a candy is present or moved, and false when the column is empty.
Part A needs both successful and unsuccessful return paths.
Defines removeNextByFlavor with Candy return type and a String parameter.
Part B returns the removed Candy object or null.
Traverses rows from bottom to top.
The search starts in the last row, not row 0.
Practice Links
