Minimum Speed to Arrive on Time
Medium · Binary Search · about 20 minutes
Asked at Google, Amazon, Microsoft, Meta.
You must take n trains in order; dist[i] is train i's distance and all trains travel at the same integer speed. Each train departs only at an integer hour, so you may wait between trains (not after the last one). Return the minimum positive integer speed to arrive within hour hours (a real number with at most two decimals), or -1 if impossible. The answer is at most 10⁷.