AP CSA FRQ Guide
2012 FRQ 3: HorseBarn
Find the index of a named horse in a barn array and consolidate horses toward the front while preserving order.
Skills Tested
What this FRQ is really practicing
Review these topics before attempting the problem.
Starter Approach
How to begin with your own plan
- 1Search through an array that may contain null entries.
- 2Move non-null horse references to earlier spaces without changing their relative order.
Attempt the problem before opening the solution.
Common Mistakes
Mistakes to watch for while writing
Self Check
Review questions before you submit
Searches safely around null barn spaces.
Check for null before calling methods on a horse.
Returns -1 when the horse is not found.
Return -1 after the full search.
Uses a target index for compaction.
A separate write index keeps order cleanly.
Sets remaining spaces to null after consolidation.
Old references at the end must be cleared.
Practice Links
