Maximize Compatible Car Riders
Reported by candidates from Uber Freight's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt on this Uber Freight OA, reported in September 2026, is trying to pick riders instead of picking a group size. Once you fix the size k, every rider's answer is a simple yes or no. That turns a subset problem into a counting problem. n goes up to 200000, so anything quadratic dies. If you blank on the counting trick during the live assessment, StealthCoder runs invisibly on your desktop and gives you the approach while you keep typing. Here's the pattern, the trap, and what to expect.
The problem
There are n riders. Rider i is willing to share a car only when the number of other selected riders is between minCoRiders[i] and maxCoRiders[i], inclusive. You may select any subset of riders. Return the maximum possible number of selected riders such that every selected rider accepts the resulting group size. Return 0 when no non-empty compatible group exists. For a group of size k, a rider is eligible exactly when minCoRiders[i] <= k - 1 <= maxCoRiders[i]. Function maximumCompatibleRiders(minCoRiders: int[], maxCoRiders: int[]) → int Examples Example 1 minCoRiders = [0,1,1,2,2] maxCoRiders = [1,2,2,4,4] return = 3 A compatible group of three can be chosen, while fewer than four riders accept having three co-riders. Example 2 minCoRiders = [0,0,0] maxCoRiders = [0,2,2] return = 2 Two riders accept one co-rider each; a group of three has only two eligible riders. Constraints 1 <= minCoRiders.length <= 200000 maxCoRiders.length == minCoRiders.length 0 <= minCoRiders[i] <= maxCoRiders[i] < n
Reported by candidates. Source: FastPrep
Pattern and pitfall
Treat k as the group size. Rider i is eligible when minCoRiders[i] <= k-1 <= maxCoRiders[i]. So each rider covers an interval of valid k values, from min+1 to max+1. Build a difference array of size n+2, add 1 at min+1 and subtract 1 at max+2, then prefix-sum it. Now count[k] is the number of riders who accept size k. A size k works only if count[k] >= k, because you need k riders who all accept it. Take the largest k where that holds, else 0. The pitfall is the off-by-one between co-riders and group size, and forgetting that eligible riders can exceed k, which is fine since you choose exactly k of them. Check Example 2: count[2] is 2, so the answer is 2. StealthCoder is your hedge if the difference array idea slips away mid-OA. The whole thing runs in O(n).
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Maximize Compatible Car 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. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderYou've seen the question.
Make sure you actually pass Uber Freight's OA.
Uber Freight reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Maximize Compatible Car Riders FAQ
What's the trick in Maximize Compatible Car Riders?+
Fix the group size k and count how many riders accept it. Each rider accepts a range of k values, so a difference array plus prefix sum gives the counts in O(n). Size k is valid when its count is at least k. Return the largest valid k.
How hard is this one really?+
Medium. The code is short, maybe 15 lines. The hard part is seeing that you choose a size, not riders. Once you see that, it's a standard interval counting problem. Most failures come from off-by-one errors, not from the algorithm.
Why can't I just sort and greedily pick riders?+
Greedy on riders fails because each rider's acceptance depends on the final group size, which you don't know yet. Sorting by min or max doesn't settle it. Testing each candidate size against a precomputed count is cleaner and avoids the circular dependency.
What edge cases should I test before submitting?+
Test n=1 with min=0 and max=0, which returns 1. Test cases where nobody is compatible, which return 0. Test max equal to n-1, so your difference array needs size n+2 to avoid an index error at max+2. Also run both examples by hand.
How do I prepare in 48 hours for this Uber Freight OA?+
Practice difference arrays and prefix sums on interval problems until the +1 and -1 placement is automatic. Then write this solution once from scratch. Focus on the translation from co-riders to group size, since that's where the reported mistakes happen.