Probes before the deadline
- O(n log n) · Hard
- Full plan
- Python
- JavaScript
- lists
- sorting
- booleans
Problem
Ilse runs the workshop on Kepler Station, where one probe is tuned per day: one on day 1, another on day 2, and so on, with no days off. Each probe launches the same day it is tuned, and it has a deadline: the last day it can still launch. Ilse chooses the order to tune them in. Write a function that takes deadlines, a list of integers from 1 up (it may be empty), and returns true if there is some order in which every probe launches on or before its deadline, or false if there is none.
With [3, 1, 2], the order 1, 2, 3 launches them on days 1, 2 and 3, each one just in time: true. With [2, 1, 1], two probes are due on day 1 and only one can launch that day: false. With no probes nothing can be late, so the empty list gives true.
Examples
The example
[3, 1, 2] → true
Two due on day 1
[2, 1, 1] → false
Plenty of time
[5, 5, 5] → true
Three for two days
[2, 2, 2] → false
A single probe, deadline 1
[1] → true
One far deadline cannot save the near ones
[1, 1, 5] → false
Besides these, the challenge has hidden tests that are revealed when you submit your solution.
You start with this
Python
def on_time(deadlines):
passJavaScript
function onTime(deadlines) {
}It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.