AP CSA 2014 FRQ 1 Scrambler

FRQ Archive2014 FRQs › FRQ 1: Scrambler
2014 AP CSA • String Manipulation

AP CSA 2014 FRQ 1: Scrambler

Complete solution, scoring rubric, and walkthrough — verified from the official College Board PDF

9 Points Medium String Manipulation Classic Format (Pre-2019)
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

Download Full 2014 FRQ 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) */ }
Timer 22:00

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).

Drag corner to expand ▽

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;
}
The skip-flag pattern: when a swap occurs, advance i by 2 instead of 1 to prevent either swapped position from participating in another swap. Use a while loop (not for loop) so you can control the increment manually.

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.

Drag corner to expand ▽

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(ArrayList wordList)
{
    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);
        }
    }
}
Backward traversal is safest for removal. set(i, scrambled) replaces in place without affecting indices. remove(i) removes safely during backward iteration.

Common Mistakes to Avoid

Not skipping i+1 after a swap

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.

Iterating forward while removing from ArrayList

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

Use a while loop for Part A — it gives you full control over how much i advances on each iteration.
In Part B, must call scrambleWord() for the dependency point. Don't reimplement the scramble logic.
For the comparison in Part B, use .equals() — not ==.

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.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]