Tap here to switch tabs
Problem
Submissions

Problem: Minimum Skips to Arrive at Meeting On Time

med
30 min
Try to solve the Minimum Skips to Arrive at Meeting On Time problem.

Statement

You are given an integer array dist of length n, where dist[i] represents the distance of the iextthi^{ ext{th}} road segment. You are also given two integers speed and hoursBefore.

You traverse each road segment in sequential order at a constant speed of speed. After completing road segment ii (where 0≤i<n−10 \leq i < n - 1), you are required to rest until the next integer hour before starting the next road segment. However, you may choose to skip a rest period, allowing you to begin the next segment immediately without waiting. There is no rest period after the final road segment.

Return the minimum number of skips needed to reach your destination within hoursBefore hours, or −1-1 if it is impossible to arrive on time.

Constraints:

  • n == dist.length

  • 1≤1 \leq n ≤1000\leq 1000

  • 1≤1 \leq dist[i] ≤105\leq 10^5

  • 1≤1 \leq speed ≤106\leq 10^6

  • 1≤1 \leq hoursBefore ≤107\leq 10^7

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Skips to Arrive at Meeting On Time

med
30 min
Try to solve the Minimum Skips to Arrive at Meeting On Time problem.

Statement

You are given an integer array dist of length n, where dist[i] represents the distance of the iextthi^{ ext{th}} road segment. You are also given two integers speed and hoursBefore.

You traverse each road segment in sequential order at a constant speed of speed. After completing road segment ii (where 0≤i<n−10 \leq i < n - 1), you are required to rest until the next integer hour before starting the next road segment. However, you may choose to skip a rest period, allowing you to begin the next segment immediately without waiting. There is no rest period after the final road segment.

Return the minimum number of skips needed to reach your destination within hoursBefore hours, or −1-1 if it is impossible to arrive on time.

Constraints:

  • n == dist.length

  • 1≤1 \leq n ≤1000\leq 1000

  • 1≤1 \leq dist[i] ≤105\leq 10^5

  • 1≤1 \leq speed ≤106\leq 10^6

  • 1≤1 \leq hoursBefore ≤107\leq 10^7