Select the maximum number of riders who can travel together given L[i] and H[i] limits.
Unlock detailed company stats for this questionUpgrade
There are N riders, and for each rider you are given two values L[i] and H[i]. If k riders are selected, every selected rider must satisfy L[i] <= k - 1 <= H[i], where k - 1 is the number of other riders traveling with that rider. Maximize the number of riders who can travel together while satisfying the condition for every selected rider. The solution should run in O(N) time.
Example: N = 5, L = [0, 1, 1, 2, 2], H = [1, 2, 2, 4, 4] gives 3.
Format · Technical interview.
Community answers
No answers contributed by the community yet.
Related questions
Find the maximum number of people who can go on a trip given each person's group size limits.Find the maximum number of riders that can fit in a car given their comfort ranges.Find the maximum number of friends who can sit together on a beach with some seats taken.Related courses

Course

Course
Course
