Fix the next reminder time in a medication app
Your task
Your medication reminder app lets someone pick a time of day for a dose. The phone keeps the time zone as a table of offset changes and works out, in UTC, when the next reminder fires.
An assistant wrote next_dose(after, dose, zone). It is in the editor. It has a bug. Find it and fix it.
Input and output:
- Times are whole minutes counted from 1970-01-01 00:00. A UTC time
ureadsu + offseton the local clock, whereoffsetis the one in force atu. Local midnights fall on multiples of 1,440. zone: pairs[starts_at, offset], sorted bystarts_at, which is a UTC time. Fromstarts_aton, the offset isoffsetminutes, until the next pair starts. The first pair starts at 0.dose: the dose's local time, in minutes after local midnight, from 0 to 1,439.after: a UTC time.- Return the first UTC time strictly after
afterat which the dose fires.
Rules the tests check:
- The dose fires once for every local date, at local time
dose. - When the clock jumps forward over
dose, that date's dose fires atdoseread with the offset in force before the jump (on a night the clock jumps from 02:00 to 03:00, a 02:30 dose fires at 03:30). - When the clock goes back so that
dosehappens twice, that date's dose fires the first time only. - Offsets are from -1,080 to 1,080 minutes. Pairs are at least 2 days apart, and two pairs in a row can have the same offset.
afteris from 10,000 to 100,000,000. The table has at most 1,000 pairs.
Then, in a sentence or two: how would you catch this kind of bug in review?
Examples
next_dose(after: int, dose: int, zone: list[list[int]]) -> intExample 1
Input
next_dose(29684880, 540, [[0, -300], [29549220, -240], [29891880, -300], [30083460, -240], [30426120, -300]])Output
29684940Example 2
Input
next_dose(29685060, 540, [[0, -300], [29549220, -240], [29891880, -300], [30083460, -240], [30426120, -300]])Output
29686380Example 3
Input
next_dose(29890920, 540, [[0, -300], [29549220, -240], [29891880, -300], [30083460, -240], [30426120, -300]])Output
29892360