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
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

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
binary search on answer
greedy partition
prefix sums
dynamic programming
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported