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.
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.
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.
n == ranges.lengthranges[i].length == 20 <= ranges[i][0] <= ranges[i][1]ranges[i][1] <= n - 1
- 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
- Convex Function MinimizationPHONE SCREEN · Seen May 2026
- Maximal Square AreaONSITE INTERVIEW · Seen May 2026
- First Unique IP Hitting the ServerPHONE SCREEN · Seen May 2026
- Jump Game with Prime-Step RuleOA · Seen May 2026
public int maxComfortableRiders(int[][] ranges) {
// write your code here
}