Skip to content

Practice Minimum Skips to Arrive at Meeting 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.

Hard#1883
LeetCode Problem

Minimum Skips to Arrive at Meeting On Time

Problem Statement

You are given an integer hoursBefore, the number of hours you have to travel to your meeting. To arrive at your meeting, you have to travel through n roads. The road lengths are given as an integer array dist of length n, where dist[i] describes the length of the ith road in kilometers. In addition, you are given an integer speed, which is the speed (in km/h) you will travel at. After you travel road i, you must rest and wait for the next integer hour before you can begin traveling on the next road. Note that you do not have to rest after traveling the last road because you are already at the meeting. However, you are allowed to skip some rests to be able to arrive on time, meaning you do not need to wait for the next integer hour. Note that this means you may finish traveling future roads at different hour marks. Return the minimum number of skips required to arrive at the meeting on time, or -1 if it is impossible.

Source: Minimum Skips to Arrive at Meeting On Time on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
dist = [1,3,2], speed = 4, hoursBefore = 2
Output
1

# Example 2

Input
dist = [7,3,5,5], speed = 2, hoursBefore = 10
Output
2

# Example 3

Input
dist = [7,3,5,5], speed = 1, hoursBefore = 10
Output
-1

Constraints

n == dist.length
1 <= n <= 1000
1 <= dist[i] <= 10^5
1 <= speed <= 10^6
1 <= hoursBefore <= 10^7

Related LeetCode Problems

Practice more problems similar to Minimum Skips to Arrive at Meeting On Time.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.