There are n riders and one car with infinite capacity. Each rider i is comfortable riding in the car only if the number of other riders also in the car is between comfort[i][0] and comfort[i][1] (inclusive). If this condition is not met, the rider will not enter the car.
All riders decide simultaneously — a valid group is a subset of riders where every rider in the group is comfortable with the group size minus one.
Return the maximum number of riders that can be in the car at the same time.
comfort = [[1, 3], [2, 4], [0, 2], [1, 3]] return = 3
With k=3 riders, each needs to be comfortable with 2 others. Riders 0 (1–3), 1 (2–4), and 2 (0–2) all include 2 in their range → valid group of 3.
With k=4, each would need 3 others. Only riders 0, 1, and 3 cover 3 — only 3 riders qualify, not 4.
comfort = [[0, 2], [0, 2], [0, 2]] return = 3
With all 3 riders, each is comfortable with 2 others (2 ∈ [0, 2]). All 3 can ride together.
comfort = [[2, 3], [2, 3]] return = 0
k=1 requires 0 others; k=2 requires 1 other. Neither 0 nor 1 falls in [2, 3] for any rider, so no valid group exists.
comfort = [[0, 0]] return = 1
The single rider is comfortable with 0 others. They ride alone.
1 ≤ n ≤ 1050 ≤ comfort[i][0] ≤ comfort[i][1] ≤ n
- 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
- Convex Function MinimizationPHONE SCREEN · Seen May 2026
- Maximal Square AreaONSITE INTERVIEW · Seen May 2026
- First Unique IP Hitting the ServerPHONE SCREEN · Seen May 2026
public int maxRiders(int[][] comfort) {
// write your code here
}