 All Problems
Minimum Speed to Arrive on Time
medium
binary search
array
amazon
google

You are given a floating-point number hour, representing the amount of time you have to reach the office. To commute to the office, you must take n trains in order. You are also given an integer array dist of length n, where dist[i] describes the distance (in kilometers) of the ith train ride.

Each train can only depart at an integer hour. Return the minimum positive integer speed (in km/h) that all the trains must travel at for you to reach the office on time, or -1 if it is impossible.

Example 1:

Input: dist = 1 3 2, hour = 6
Output: 1

Example 2:

Input: dist = 1 3 2, hour = 2.7
Output: 3

Input format: First line: dist array. Second line: hour (decimal).

Output format: Minimum speed or -1.

Run to check your code against the sample cases, or submit to run every case