Ahaan

FRQ 1 Homework 2017

FRQ 1 Homework 2017

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. Extracting Digits with % 10 and / 10: Using num % 10 to get the last digit and num / 10 to remove it is the standard way to break an integer into its individual digits without converting to a String.

  2. Inserting at Index 0 for Correct Order: Since digits are extracted from right to left, using digitList.add(0, digit) inserts each digit at the front of the ArrayList, preserving the original left-to-right order.

  3. Handling the Edge Case of Zero: When num == 0, the while loop never executes, so explicitly adding 0 to the list before the loop ensures the special case is handled correctly.

  4. Comparing Adjacent Elements for Strictly Increasing: In isStrictlyIncreasing, looping from index 0 to size() - 2 and checking get(i) >= get(i + 1) catches both equal and decreasing pairs — returning false immediately on the first violation.

  5. Early Return Pattern: Returning false as soon as a non-increasing pair is found avoids unnecessary iterations. If the entire loop completes without returning, then all pairs are strictly increasing and we return true.

Area of Improvement

My main struggle was getting the digits in the correct order. I initially used digitList.add(num % 10) without inserting at index 0, which produced the digits in reverse. I also initially used > instead of >= in isStrictlyIncreasing, which incorrectly allowed equal adjacent digits to pass. Remembering to handle num == 0 as a special case was another easy thing to overlook since the while loop condition num > 0 skips it entirely.

Scroll to top