FastPrepMaximum Comfortable Riders
Problems/Maximum Comfortable Riders

Maximum Comfortable Riders

Uber logoUberFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem 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[][]) → 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

More Uber problems

  • Worst-Performing Ads by CTR in a Campaign TreePHONE SCREEN · Seen Nov 2026
  • Earliest Time All Users Are ConnectedPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Max Points on a LinePHONE SCREEN · Seen Oct 2026
All Uber interview questionsSee Uber hiring insights
Saved
class Solution {
    public int maxComfortableRiders(int[][] ranges) {
      // write your code here
    }
}
Checking account…