Proof of Completion for First Part

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
-
Tracking Consecutive Free Minutes: In
findFreeBlock, I used a counter that increments for each free minute and resets to 0 when a reserved minute is encountered. This is a common pattern for finding consecutive sequences in an array or list. -
Calculating the Start of a Block: Once the counter reaches the desired duration, the starting minute is
minute - duration + 1. Getting this formula right was key to returning the correct index. -
Iterating Across Periods: In
makeAppointment, looping fromstartPeriodtoendPeriodand callingfindFreeBlockfor each period demonstrates how to delegate work to a helper method and act on its return value. -
Using Return Values as Flags: Checking
findFreeBlock != -1to decide whether to reserve the block reinforced the idea of using sentinel return values (-1) to signal failure vs. success. -
Calling Multiple Methods Together:
makeAppointmentcalls bothfindFreeBlockandreserveBlock, showing how methods work together — one searches, one acts, and the caller coordinates both.
Area of Improvement
My main struggle was correctly computing the starting minute of the free block. I initially returned minute instead of minute - duration + 1, which gave the last minute of the block rather than the first. I also had to be careful about resetting the free counter to 0 (not 1) when hitting a reserved minute, and remembering that makeAppointment should stop searching as soon as the first valid block is found and reserved.