Dsa
Intervals
Easy
Cinema Row Optimizer
A cinema row has L seats, indexed 0 to L-1. Some ranges of seats are already blocked due to maintenance or bookings. You are given N blocked intervals [start, end] (both inclusive). You need to find the maximum number of groups of size K that can be seated in the remaining available seats. Each group must sit in a continuous block of seats, and groups cannot overlap with blocked seats or each other.
Input Format:
The first line contains three integers: L (row length), N (number of blocked intervals), and K (group size).
The next N lines each contain two integers: start and end of a blocked range.
Output Format:
Print the maximum number of groups of size K that can fit.
Example:
Input:
20 2 3
5 7
14 15
Output:
4
Explanation: Free blocks are [0,4] (size 5), [8,13] (size 6), and [16,19] (size 4). Groups of 3: 5//3=1, 6//3=2, 4//3=1. Total: 1+2+1 = 4.
Key concepts
intervalsgreedy
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now