I got wrong answer in this problem. I am not sure what is the mistake in my idea or code. I will be grateful if anyone provide a test case or debug my code.
My idea–> I at first sorted all the start and end value accordingly and kept their type and id. if first lecture’s starting time is greater than second one then i swapped them such that 1 comes earlier than 2.
I maintained so far free or available rooms in a deque. Whenever I’m facing an end value I pushed the room into the deque because this room gets free. For a start value if no available rooms are there then i allocated a new room as we have no other option to allocate it into a previously allocated room. But if we have free rooms and the id of the current lecture isn’t 2, we can safely assign that lecture in any of the currently available free rooms in deque. But if id is 2 then i checked if the room for lecture 1 is already present as free room in the deque. if this is true, then we have to use another free room except the room of 1. But if we have only one free room and that room is the room of lecture 1, then we need to allocate another new room because as per the problem 1 and 2 can’t be allocated in the same room. This is the the overall idea.
My Pastebin Solution Link