You are building a real-time leaderboard for an Escape Room Center that has sequential rooms labeled to . When the game begins, each of participants starts in room 0 and can only move to the next room after solving its puzzle. Even if several players occupy the same room, they all solve independently at their own pace.
Your leaderboard needs to track players' progress and support fast queries about room populations and top performers. In particular, whenever a player advances to the next room.
Implement the EscapeRoom class:
-
EscapeRoom(int numRooms, int maxParticipants)Initialize the game withnumRoomsrooms and capacity formaxParticipantsplayers. -
void registerParticipant(String participantId)Register a new participant in room 0. -
boolean increment(String participantId)AdvanceparticipantIdplayer from their current room to the next room. Returnfalseif the ID doesn't exist or is already in the last room. Otherwise, returntrue. -
int countParticipantsInRoom(int room)
Return the number of players currently inroom. Ifroomis invalid (less than 0 or ≥ numRooms), it returns 0. -
String[] getTopParticipants(int k)
Return up tokparticipant IDs who have made the most progress in the game. If multiple participants are in the same room, prioritize those who entered the room earlier. Ifkexceeds the total number of registered participants, only the available IDs are returned.
Constraints:
≤numRooms≤≤maxParticipants≤- Total number of method calls ≤
Example
Input: ["EscapeRoom", "registerParticipant", "registerParticipant", "registerParticipant", "registerParticipant", "increment", "increment", "increment", "increment", "increment", "countParticipantsInRoom", "countParticipantsInRoom", "countParticipantsInRoom", "countParticipantsInRoom", "getTopParticipants"] [[4, 4], ["P0"], ["P1"], ["P2"], ["P3"], ["P2"], ["P2"], ["P2"], ["P0"], ["P3"], [0], [1], [2], [3], [2]]
Output: [null, null, null, null, null, true, true, true, true, true, 1, 2, 0, 1, ["P2", "P0"]]
Explanation: Initial state:
final state:
EscapeRoom room = new EscapeRoom(4, 4);// Create 4-room game with maximum of 4 participants.room.registerParticipant("P0");// register participant P0room.registerParticipant("P1");room.registerParticipant("P2");room.registerParticipant("P3");room.increment("P2");// Returns true. "P2" → room 1room.increment("P2");// Returns true. "P2" → room 2room.increment("P2");// Returns true. "P2" → room 3room.increment("P0");// Returns true. "P0" → room 1room.increment("P3");// Returns true. "P3" → room 1room.countParticipantsInRoom(0);// Returns 1. Only "P1" is in room 0.room.countParticipantsInRoom(1);// Returns 2. "P0" and "P3" are in room 1.room.countParticipantsInRoom(2);// Returns 0.room.countParticipantsInRoom(3);// Returns 1. Only "P2" is in room 3.room.getTopParticipants(2);// Returns ["P2", "P0"], as "P2" (in room 3) made most progress in the game. "P0" and "P3" are both in room 1, and "P0" is prioritized because it entered the room earlier.


