Room Allocation
You are given an array customers of size n, where customers[i] = [arrival, departure] represents the stay of the ith customer.
Two customers can share a room if the first customer departs strictly before the second customer arrives (departure1 < arrival2).
Find the minimum number of rooms k required to accommodate all customers. Return an array of size n + 1 where:
- The first element is k.
- The remaining n elements are the room assignments (numbered 1 to k) for each customer, in their original input order.
Note: If there are multiple valid room allocations, you can return any of them.
Example 1:
Input: customers = [[1, 2], [2, 4], [4, 4]]
Output: [2, 1, 2, 1]
Explanation:
k = 2 minimum rooms are needed. Customer 0 and 1 overlap on day 2, so they need different rooms. Customer 1 and 2 overlap on day 4. Customer 0 and Customer 2 can share a room. [2, 2, 1, 2] would also be accepted.
Example 2:
Input: customers = [[1, 2], [3, 4], [5, 6]]
Output: [1, 1, 1, 1]
Explanation:
None of the stays overlap. A single room can accommodate everyone sequentially. There is only one room to choose from.
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= customer.length <= 200,000
- customers[i].length == 2
- 1 <= arrival <= departure <= 109