Fewest Two-Seat Shuttles to Move Everyone Under a Weight Limit
Last updated: November 29, 2026
Quick Overview
Each Google campus shuttle seats at most two riders and carries at most a given total weight. Given rider weights, all at most the limit, return the minimum number of shuttle trips needed to move everyone.
0
0
0 solved
Each Google campus shuttle seats at most two riders and carries at most a given total weight. Given rider weights, all at most the limit, return the minimum number of shuttle trips needed to move everyone.
A greedy two-pointer question in the style of Google phone screens. The interviewer checks that the candidate pairs the heaviest rider with the lightest when possible and can justify why that greedy choice is optimal.
What the Interviewer Expects
- Sorts weights and uses pointers at both ends
- Always sends the heaviest rider on each trip
- Pairs the lightest rider when the sum fits
- Gives an exchange argument for optimality
- States O(n log n) time
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
- What if shuttles hold up to three riders?
- What if weights are bounded small integers; can you avoid the sort?
- How would you return the actual pairings?
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
wof positive integers, each<= limit. - Each trip carries one or two riders with combined weight
<= limit. - Output: minimum number of trips....
High-Level Design
Sort weights. Put lo at the lightest and hi at the heaviest. Every trip carries the heaviest remaining rider w[hi]. If w[lo] + w[hi] <= limit, the lightest rider rides along, so advance lo. ...