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
-
Extracting Digits with
% 10and/ 10: Usingnum % 10to get the last digit andnum / 10to remove it is the standard way to break an integer into its individual digits without converting to a String. -
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. -
Handling the Edge Case of Zero: When
num == 0, the while loop never executes, so explicitly adding0to the list before the loop ensures the special case is handled correctly. -
Comparing Adjacent Elements for Strictly Increasing: In
isStrictlyIncreasing, looping from index 0 tosize() - 2and checkingget(i) >= get(i + 1)catches both equal and decreasing pairs — returningfalseimmediately on the first violation. -
Early Return Pattern: Returning
falseas 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 returntrue.
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.