Night owl sleep log
EasyOnline Assessment
Find the nights on which a sleep tracker says you slept less than your goal.
Each night the tracker stores two clock times in 24-hour "HH:MM" format: when you went to bed and when you woke up. You always wake up at the first moment the clock shows the wake time after going to bed, so if the wake time looks earlier than the bedtime, you slept through midnight ("23:15" to "06:40" is 7 hours 25 minutes). Nobody sleeps more than one full day.
There is one exception: if the bedtime and the wake time are identical, the watch was left on the nightstand. Such a night is not recorded: it counts as neither short nor long and is skipped.
A recorded night is short if you slept strictly fewer than goal minutes.
Input: logs, a list of [bed, wake] pairs of strings, one per night, with the first night first; goal, an integer number of minutes.
Output: a list of the 1-based numbers of the short nights, in increasing order. If there are none, return [].
Example 1
- Input:
- [[["23:15","06:40"],["00:30","07:30"],["22:00","22:00"],["21:45","05:30"]],450]
- Output:
- [1,2]
- Explanation
- Night 1: 23:15 to 06:40 crosses midnight and lasts 45 + 400 = 445 minutes, below 450. Night 2: 00:30 to 07:30 is 420 minutes, also short. Night 3 has the same bedtime and wake time, so the watch was left on the nightstand and the night is skipped. Night 4: 21:45 to 05:30 is 465 minutes, enough. Answer: nights 1 and 2.
Example 2
- Input:
- [[["23:00","07:00"],["23:59","00:00"],["12:00","11:59"]],480]
- Output:
- [2]
- Explanation
- 23:00 to 07:00 is exactly 480 minutes, which meets a goal of 480, so it is not short. 23:59 to 00:00 is a single minute, which is short. 12:00 to 11:59 is 1,439 minutes, nearly a full day, which is long enough. Answer: night 2.
Example 3
- Input:
- [[["10:00","10:00"],["03:30","03:30"]],1]
- Output:
- []
- Explanation
- With a goal of 1 minute, nothing recorded can fall below it, and the unrecorded nights (identical times) are skipped, so the result is an empty list.
Constraints
0 <= logs.length <= 60- every time is a valid 24-hour clock time written
"HH:MM", from"00:00"to"23:59" 1 <= goal <= 1,440