Opening your workspace…
Workspace/Coding room
Opening your workspace…
At the cuttlefish nursery, the keeper wants to dim the tank lights and watch the hatchlings settle. Feedings and filter rinses interrupt the watch. Given the shift length and a log of busy intervals, return the longest uninterrupted quiet interval as [start, end]. Choose the earliest if several tie. Return [] if the whole shift is busy.
30, [[18,21],[4,9],[7,12],[23,30]]Output[12,18]The jobs at minutes 4 and 7 keep the tank busy through minute 12. The quiet spells last 4, 6, and 2 minutes, so the keeper starts at minute 12.
20, [[12,15],[5,7]]Output[0,5]The keeper has five quiet minutes before the first job, five between jobs, and five after the last. The earliest watch starts at minute 0.
Merge busy intervals in time order and measure the gaps, including the end of the shift.
function solve(shift, busy) { // Write your solution here. }
Tab inserts two spaces. Shift+Tab outdents. Use the arrow keys and Tab to choose a suggestion. Press Escape, then Tab, to leave the editor. Press Control or Command with apostrophe to run samples or with Enter to submit.