Optimal Seat Allocation Fairness Index
Optimal Seat Allocation Fairness Index
HardArrays100% accepted
Indian Railways wants to allocate consecutive seats to family groups while minimizing dissatisfaction. Given groups needing specific seat counts and total seats available, find allocation minimizing total gap between needed and allocated seats.
Approach
Seat groups one by one in the given order into a coach with total_seats seats. A group boards only if its full size fits in the remaining seats (else it is skipped; later groups still tried). Return how many groups board. solve(groups, total_seats).
Input
groups=[4,3,2], total_seats=12
Output
3
More Arrays problems
Browse all coding problems →solution.py
Loading editor...
Test 1
Test 2
Test 3
Press Run to test your custom input, or Submit to judge against all test cases.
Sign in to continue
Create a free account to run code, submit solutions and track progress.
- Free forever — no credit card
- 10+ languages with live execution
- Points, streaks & leaderboards