Leetcode Problem 1870. Minimum Speed to Arrive on Time

1870. Minimum Speed to Arrive on Time

Leetcode Solutions

Key approach of the solution: Binary Search

  1. Initialize left to 1 and right to 10^7.
  2. While left is less than or equal to right: a. Calculate mid as the average of left and right. b. Calculate the time required to travel with speed mid. c. If the time required is less than or equal to hour, update minSpeed to mid and set right to mid - 1. d. If the time required is greater than hour, set left to mid + 1.
  3. Return minSpeed if it is not -1, otherwise return -1 if it is impossible to reach on time.
UML Thumbnail

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...