Practice Minimum Speed to Arrive on Time
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
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 sequential 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, so you may need to wait in between each train ride. Return the minimum positive integer speed (in kilometers per hour) that all the trains must travel at for you to reach the office on time, or -1 if it is impossible to be on time. Tests are generated such that the answer will not exceed 10^7 and hour will have at most two digits after the decimal point.
Source: Minimum Speed to Arrive on Time on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
dist = [1,3,2], hour = 6
1
# Example 2
dist = [1,3,2], hour = 2.7
3
# Example 3
dist = [1,3,2], hour = 1.9
-1
Constraints
Related LeetCode Problems
Practice more problems similar to Minimum Speed to Arrive on Time.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.