Maximum Comfortable Riders
Learn this problemProblem statement
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[][]) → intExamples
Example 1
ranges = [[0,2],[1,3],[2,4],[3,5]]return = 3If 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 = 1Two 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.lengthranges[i].length == 20 <= ranges[i][0] <= ranges[i][1]ranges[i][1] <= n - 1
More Uber problems
- Minimum Refueling StopsONSITE INTERVIEW · Seen Jul 2026
- Last Truck to Leave the LaneOA · Seen Jul 2026
- Chain of CommandOA · Seen Jul 2026
- Jump Game with Prime-3 StepsOA · Seen Jun 2026
- Total Palindrome Substring CostOA · Seen Jun 2026
- Earliest Time All Users Are ConnectedPHONE SCREEN · Seen May 2026
- Tournament Rounds by RankPHONE SCREEN · Seen May 2026
- Farthest Seat AssignmentONSITE INTERVIEW · Seen May 2026