You are given an array dist where dist[i] represents the distance of the ith train ride, and a floating-point number hour representing the total time available. Each train can only depart at an integer hour. This means after finishing a train ride, you may need to wait until the next integer hour before starting the next train, except for the last train which does not require waiting.
Return the minimum integer speed required to travel all distances within the given hour. If it is not possible to arrive on time, return -1.
Example 1
Input: dist = [1,3,2], hour = 6
Output: 1
Explanation: At speed 1, travel times are 1, 3, and 2 hours. Total time = 6 hours, so speed 1 is sufficient.
Example 2
Input: dist = [1,3,2], hour = 2.7
Output: 3
Explanation: At speed 3, travel times are ceil(1/3) = 1, ceil(3/3) = 1, and 2/3 ˜ 0.67. Total time ˜ 2.67 hours, which is within 2.7 hours.
Example 3
Input: dist = [1,3,2], hour = 1.9
Output: -1
Explanation: Even at very high speed, the minimum possible time is greater than 1.9 hours due to waiting between trains, so it is impossible.
Sign in to write, run, and submit your solution against the full test suite.