AP CSA 2014 FRQ 1 Scrambler
AP CSA 2014 FRQ 1: Scrambler
Complete solution, scoring rubric, and walkthrough — verified from the official College Board PDF
| Question Type | String Manipulation |
| Key Skills | Write scrambleWord() (swap each 'A' + non-'A' pair in a single left-to-right pass; once swapped, neither position can sw |
| Difficulty | Medium |
| AP CSA Units | Unit 1: Using Objects & Methods (String manipulation, charAt, substring) and Unit 4: Data Collections (ArrayList backward removal). |
What This Problem Asks
Write scrambleWord() (swap each 'A' + non-'A' pair in a single left-to-right pass; once swapped, neither position can swap again) and scrambleOrRemove() (apply to each word in an ArrayList; remove words that are unchanged after scrambling).
Official Question & PDF
PDF cannot display here. Open PDF directly →
Provided Code
// Both methods are static in an unnamed class
public static String scrambleWord(String word) {
/* part (a) */
}
public static void scrambleOrRemove(ArrayList wordList) { /* part (b) */ }
Part A — scrambleWord (6 Points)
Write scrambleWord(). Return a scrambled version of word: scan left to right; if position i has 'A' and position i+1 has a non-'A', swap those two characters and skip position i+1 (so it cannot be swapped again).
Scoring Rubric
| +1 | Uses a loop to process each character |
| +1 | Detects 'A' followed by non-'A' pair |
| +1 | Swaps the two characters correctly |
| +1 | Skips i+1 after a swap (no re-swapping) |
| +1 | Handles edge cases (empty string, no swap, all A's) |
| +1 | Returns correct scrambled string (algorithm) |
Solution
public static String scrambleWord(String word)
{
String result = "";
int i = 0;
while (i < word.length() - 1)
{
if (word.charAt(i) == 'A' && word.charAt(i + 1) != 'A')
{
result += word.charAt(i + 1);
result += word.charAt(i);
i += 2; // skip both — neither can be re-swapped
}
else
{
result += word.charAt(i);
i++;
}
}
// Append last character if not already consumed by a swap
if (i < word.length())
{
result += word.charAt(i);
}
return result;
}
Part B — scrambleOrRemove (3 Points)
Write scrambleOrRemove(). For each word in wordList: if scrambleWord(word) differs from word, replace it with the scrambled version; otherwise remove it from the list.
Scoring Rubric
| +1 | Calls scrambleWord() on each word |
| +1 | Replaces unchanged words with scrambled version when different |
| +1 | Removes words that are unchanged (backward traversal or correct index management) |
Solution
public static void scrambleOrRemove(ArrayListwordList) { for (int i = wordList.size() - 1; i >= 0; i--) { String word = wordList.get(i); String scrambled = scrambleWord(word); if (scrambled.equals(word)) { wordList.remove(i); } else { wordList.set(i, scrambled); } } }
Common Mistakes to Avoid
Wrong
i++; // only advances by 1 — allows re-swapping of position i+1
Correct
i += 2; // skip both positions — neither can be in another swap
If you advance by only 1 after a swap, position i+1 (which was just swapped) can participate in another swap with position i+2. The rule says once a position is swapped, it cannot swap again.
Wrong
for (int i = 0; i < wordList.size(); i++) { if (same) wordList.remove(i); }
Correct
for (int i = wordList.size()-1; i >= 0; i--) { if (same) wordList.remove(i); }
Forward removal shifts indices of subsequent elements. Backward removal is safe because removing index i does not affect any index < i.
Exam Tips
Frequently Asked Questions
What does 2014 AP CSA FRQ 1 Scrambler ask?
Part A asks students to write scrambleWord(), which scans left to right and swaps each 'A' followed by a non-'A', preventing any position from being swapped twice. Part B asks for scrambleOrRemove(), which applies scrambleWord() to each ArrayList entry and removes those that were unchanged.
What is the hardest part of scrambleWord()?
Correctly implementing the skip: after swapping positions i and i+1, advance i by 2 (not 1) so that neither position can participate in another swap. Using a regular for loop makes this hard — a while loop where you control the increment explicitly is much cleaner.
See All 2014 AP CSA FRQs
View the complete 2014 exam hub with solutions, difficulty analysis, and scoring for all four questions.
View 2014 FRQ Hub →Get in Touch
Whether you're a student, parent, or teacher — I'd love to hear from you.
Just want free AP CS resources?
Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
Prefer email? Reach me directly at [email protected]