Ahaan

FRQ 4 Homework 2019

FRQ 4 Homework 2019

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

  1. 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.

  2. 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.

  3. Iterating Across Periods: In makeAppointment, looping from startPeriod to endPeriod and calling findFreeBlock for each period demonstrates how to delegate work to a helper method and act on its return value.

  4. Using Return Values as Flags: Checking findFreeBlock != -1 to decide whether to reserve the block reinforced the idea of using sentinel return values (-1) to signal failure vs. success.

  5. Calling Multiple Methods Together: makeAppointment calls both findFreeBlock and reserveBlock, 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.

Scroll to top