Maximum Comfortable Riders
Reported by candidates from Uber's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Uber's April 2026 OA has a question that looks like a puzzle and is really a counting problem. Maximum Comfortable Riders gives you ranges of acceptable "other riders" and asks for the biggest group that keeps everyone happy. Most people lock onto the first idea that comes to mind, then watch it fail on example two. The pattern is a sweep over group sizes with a difference array. It's short once you see it. If you blank during the live assessment, StealthCoder runs invisibly on your desktop and can hand you the approach while you type.
The problem
There are n riders and one car with unlimited capacity. Each rider has a comfort range for how many other riders they are willing to share the car with. You are given ranges, where ranges[i] = [minOthers, maxOthers] means rider i will ride only if the final car contains at least minOthers and at most maxOthers other riders. Return the maximum number of riders that can be placed in the car so that every chosen rider is comfortable with the final group size. Function maxComfortableRiders(ranges: int[][]) → int Examples Example 1 ranges = [[0,2],[1,3],[2,4],[3,5]] return = 3 If 3 riders are chosen, each chosen rider has 2 other riders in the car. The first three riders are all comfortable with 2 others. Choosing 4 riders would require 4 riders who are comfortable with 3 others, but only three riders satisfy that. Example 2 ranges = [[0,0],[0,0],[1,2]] return = 1 Two riders are comfortable riding alone, so a group of size 1 is possible. No group of size 2 is possible because only one rider is comfortable with exactly one other rider. Constraints n == ranges.length ranges[i].length == 2 0 <= ranges[i][0] <= ranges[i][1] ranges[i][1] <= n - 1
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: fix a group size k. Every chosen rider sees k-1 others, so rider i qualifies if minOthers <= k-1 <= maxOthers. Count how many riders qualify for each k. If that count is at least k, you can pick k of them, and every one is comfortable. Build the counts with a difference array: add 1 at minOthers, subtract 1 at maxOthers+1, then prefix sum. Check k from n down to 1 and return the first k where count[k-1] >= k. The common pitfall is sorting by min or max and greedily taking riders. That ignores that the group size itself changes what each rider sees. Another slip is forgetting the others versus total off-by-one. Example one shows it: size 3 means 2 others. The whole thing runs in O(n). If you freeze, StealthCoder is the safety net for the live OA.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Maximum Comfortable Riders cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Uber's OA.
Uber reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Maximum Comfortable Riders FAQ
What's the trick in Maximum Comfortable Riders?+
Stop thinking about which riders to pick and think about the final group size k. A rider fits if k-1 lies inside their range. Count riders who fit each k, then find the largest k where that count is at least k.
How hard is this one really?+
Easier than it looks. There's no heavy data structure. It's a difference array plus a prefix sum and a final scan. The hard part is the reframing. Once you iterate over group sizes instead of riders, the code is about ten lines.
Why does greedy sorting fail here?+
Sorting by min or max and adding riders one at a time ignores that adding a rider changes everyone else's others count. A rider who was fine at size 2 may break at size 3. Fixing k first avoids that.
What's the off-by-one people hit?+
The range counts other riders, not the group. For a group of size k, each rider has k-1 others. Index your difference array by others, then compare the count at k-1 against k. Example one confirms it: 3 riders means 2 others.
How do I prepare for this in 48 hours?+
Practice the difference array and prefix sum pattern on interval-coverage problems. Then solve this one by hand on both examples. Check edge cases like all ranges [0,0], where the answer is 1, and the full-range case where the answer is n.