Split a Day of Back-to-Back Trips Into K Shifts Fairly
Last updated: November 29, 2026
Quick Overview
A driver's trips for the day have durations in order. Split them into exactly k contiguous shifts (each non-empty) so that the longest shift is as short as possible, and return that length.
Uber
November 29, 20260
0
0 solved
A driver's trips for the day have durations in order. Split them into exactly k contiguous shifts (each non-empty) so that the longest shift is as short as possible, and return that length.
An Uber onsite question on driver wellbeing and hours limits, testing binary search on the answer over a sum. Interviewers check the bounds, the greedy check, and why contiguity matters.
What the Interviewer Expects
- Sets the search range from max(trip) to sum(trips)
- Greedy check counts shifts needed when no shift exceeds a cap
- Explains that fewer shifts than k is fine because shifts can be split further
- Handles k equal to the number of trips
- Mentions the DP alternative and its cost
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Return the actual split points.
- What if each shift also needs a minimum break between shifts?
- How would you solve it with dynamic programming and when is that preferable?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: list of positive durations,
1 <= k <= len(trips). - Output: the minimum possible maximum shift total.
- Order must be preserved; shifts are contiguous....
High-Level Design
Given a cap C, greedily pack trips into the current shift until the next trip would exceed C, then start a new one. This uses the fewest shifts possible under cap C. If that count is at most k, C is f...