Ahaan

FRQ 1 Homework 2014

FRQ 1 Homework 2014

Proof of Completion and Running on Open Coding Society Code Runner Part A

Proof of Completion and Running on Open Coding Society Code Runner Part B

Key Takeaways

  1. String Manipulation with substring(): Building a new string by combining parts of the original using substring(), charAt(), and string concatenation is a core technique for rearranging characters.

  2. While Loop vs For Loop for List Removal: When removing elements from a list while iterating, a while loop with manual index control avoids skipping elements. Only increment the index when you don’t remove.

  3. Comparing Strings with .equals(): Always use .equals() to compare string content in Java, never ==. This was critical in scrambleOrRemove to check if the word changed.

  4. Pattern Matching in Strings: Scanning for a specific pattern (like ‘A’ followed by a non-‘A’) requires checking consecutive characters with charAt(i) and charAt(i + 1), while being careful not to go out of bounds.

  5. Modifying a List In-Place: Using wordList.set(i, value) to replace and wordList.remove(i) to delete lets you modify the original list directly without creating a new one.

Area of Stuggle

One thing I noticed while working through this FRQ is that string manipulation in Java can get tricky fast. Building a new string with substring() and charAt() makes sense conceptually, but getting the indices right took some trial and error. I kept making small mistakes like being off by one on the substring boundaries, which would either cut off a character or duplicate one The other part that tripped me up was modifying a list while looping through it. My first instinct was to use a regular for loop going forward, but that caused elements to get skipped after a removal. Switching to a while loop where I only increment the index when I don’t remove fixed that, but it took a few debug cycles to realize why elements were being skipped in the first place. This is definitely a pattern I need to work on for the AP Exam.

Scroll to top