Minimize the Longest Hike Between Rest Stops
Updated
Problem statement
You are given an array segments, where segments[i] is the positive hiking time of the ith consecutive segment of one route, and an integer restStops.
Place every rest stop between two adjacent segments. Using exactly restStops rest stops divides the route into exactly restStops + 1 nonempty continuous hiking groups. The duration of a group is the sum of its segment times.
Return the minimum possible value of the maximum group duration. You only need to return this minimum duration; you do not need to reconstruct a placement.
Function
minimizeLongestHike(segments: int[], restStops: int) → longExamples
Example 1
segments = [7,2,5,10,8]restStops = 1return = 18Place the rest stop after the third segment. The two group durations are 14 and 18. Every other placement has a maximum duration of at least 18.
Example 2
segments = [4,2,7,3,6]restStops = 2return = 9Use groups [4,2], [7], and [3,6], whose durations are 6, 7, and 9. A maximum below 9 cannot fit these segments into three groups.
Example 3
segments = [6,3,8]restStops = 2return = 8Every segment forms its own group, so the longest continuous hike is the longest individual segment.
Constraints
1 <= segments.length <= 100000.1 <= segments[i] <= 10^9.0 <= restStops < segments.length.- The sum of all segment times fits in a signed 64-bit integer.
More Pinterest Onsite Interview questions
- Minimum Bus Routes to a DestinationPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Delete and Compact a Forest SubtreePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Filter Pins by Excluded IDsONSITE INTERVIEW · Seen Oct 2026
- Top-Scoring Items in a Time WindowONSITE INTERVIEW · Seen Oct 2026
- Optimal Account BalancingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Escape Room LeaderboardPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Policy Violation Set ChecksONSITE INTERVIEW · Seen Sep 2026
- Shortest Sequence of Source SubsequencesONSITE INTERVIEW · Seen Sep 2026
- Insert Addition and Multiplication OperatorsONSITE INTERVIEW · Seen Sep 2026
- Unique Active Pins by Time SegmentONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Capacity to Ship Packages Within DaysMicrosoft · OA · ONSITE INTERVIEWMicrosoft interview questions
- Minimum Daily Printing LimitAgoda · ONSITE INTERVIEWAgoda interview questions
- Minimize Maximum Pilot WorkloadSpotnana · ONSITE INTERVIEWSpotnana interview questions
- Maximize the Minimum Distance Between RobotsAmazon · ONSITE INTERVIEW
- Minimum Processing Speed with Multiple RidersDoorDash · ONSITE INTERVIEWDoorDash interview questions
- Split Array Largest SumBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Rock JumpingIMC Trading · OAIMC Trading interview questions
- Minimize Maximum Group DifferenceDRW · OADRW interview questions
- Array NullificationQRT · OA
- Minimize the Maximum Pages AllocatedGoogle · PHONE SCREENGoogle interview questions