Fewest Two-Seat Pool Cars for Riders Under a Luggage Limit
Last updated: November 29, 2026
Quick Overview
Each rider has a luggage weight and each pool car can carry at most two riders with total luggage at most L; given all weights (each at most L), return the minimum number of cars needed.
Uber
November 29, 20260
0
0 solved
Each rider has a luggage weight and each pool car can carry at most two riders with total luggage at most L; given all weights (each at most L), return the minimum number of cars needed.
UberX Share and pooled products constantly trade off matching quality against capacity. This screen question checks that you can find and justify the greedy pairing, then implement it with sorting and two pointers.
What the Interviewer Expects
- Sort the weights
- Pair the heaviest rider with the lightest when possible
- Prove the greedy choice by an exchange argument
- Implement in O(n log n)
- Handle odd counts and riders who must ride alone
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 a car can carry up to three riders?
- What if riders also have pickup locations and pairs must be within 2 km?
- 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
weightswith eachw <= L, integerL. - Each car holds one or two riders; total weight must be
<= L. - Output: minimum number of cars....
High-Level Design
Sort ascending and keep i at the lightest and j at the heaviest unassigned rider. The heaviest rider needs a car either way. If the lightest rider fits with them, pairing them is never worse: in a...