Opening your workspace…
Workspace/Coding room
Opening your workspace…
At midnight the radio host in Lavender Town takes a request for the Poké Flute tune. He gets three notes in before a burst of static cuts him off. The caller rings back. Her Snorlax has opened one eye, and could he please try that again from the beginning?
There's a log of the interference beside the mixing desk. Each entry gives a period, a phase, and a duration, all in seconds. The first burst starts at the phase, measured from midnight. Another starts one period later, and so on. For instance, [5,1,2] means you lose seconds 1 and 2, then 6 and 7. At second 3 you can hear the music again. Several sources of static can be on air at once.
You need enough consecutive quiet seconds to play the whole tune. Return the earliest whole second you can start and still finish by the following midnight, or -1 if the caller will have to wake her Snorlax herself.
3, [[5,1,1]]Output2Static cuts out second 1. At second 2 the station can play three seconds before the next burst at 6.
2, [[4,0,1]]Output1Static occupies [0,1), [4,5), and so on. Starting at 0 overlaps the first burst; starting at 1 ends at 3, safely before the next one.
Mark the start and end of each static burst, then scan for a sufficiently long quiet run.
function solve(melodyLength, bursts) { // 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.