Skip to main content

AP CSA FRQ Guide

2008 FRQ 2: StringCoder

Decode a list of string parts by joining substrings from a master string, then encode a word by repeatedly finding a part that matches its remaining prefix.

Substring Encoding with ArrayList22 minute targetStringArrayListsubstringobjectshelper methods

Skills Tested

What this FRQ is really practicing

StringArrayListsubstringobjectshelper methods

Review these topics before attempting the problem.

Starter Approach

How to begin with your own plan

  1. 1Part A: retrieve the substring at each StringPart start with its specified length and concatenate the substrings in list order.
  2. 2Part B: use findPart to match the beginning of the remaining word, append that StringPart to the result, and advance by its length.
  3. 3Continue encoding until the entire word is represented, preserving the part order.

Attempt the problem before opening the solution.

Common Mistakes

Mistakes to watch for while writing

Using the part length as an absolute substring end index.
Calling findPart on the original word on every iteration.
Failing to consume a matched prefix or changing the order of parts.

Self Check

Review questions before you submit

Uses each part start and length when decoding.

The substring end index is start plus length.

Retrieves substrings from the master string.

Append each retrieved substring in the original list order.

Uses the supplied findPart helper when encoding.

Do not replace the helper with a separate matching algorithm.

Advances past each encoded prefix.

Each findPart result has positive length; consume that many characters.

Practice Links

Where to go next