FastPrepEscape Room Leaderboard
Problems/Escape Room Leaderboard

Escape Room Leaderboard

Pinterest logoPinterest● MediumFULLTIMENEW GRADPHONE SCREENONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report defines constant-time player advancement and room lookup plus a top-k leaderboard ordered by room and room-entry time. It omits a portable batch interface and operation result encoding. The judged core task matches the visible source at about 94%.

Players progress through escape rooms numbered from 0 through roomCount. Every player in players begins in room 0. Their initial entry order into room 0 is their order in players.

Process operations in order:

  • ADVANCE playerId: move the player from room r to room r + 1 and return the new room as a decimal string. The operation is valid only when r < roomCount.
  • GET playerId: return the player's current room as a decimal string.
  • LEADERBOARD k: return up to k player identifiers, ordered by decreasing room number. Players in the same room are ordered by when they entered that room; earlier entry comes first. Encode the identifiers as one comma-separated string, or an empty string when k == 0.

Return one result string for every operation. The intended data structure supports ADVANCE and GET in constant time and LEADERBOARD in O(roomCount + k) time.

Function

runEscapeRoomLeaderboard(players: String[], roomCount: int, operations: String[]) → String[]

Examples

Example 1

players = ["A","B"]roomCount = 3operations = ["ADVANCE A","ADVANCE B","ADVANCE A","LEADERBOARD 2","GET B"]return = ["1","1","2","A,B","1"]

A reaches room 2 while B remains in room 1, so the leaderboard is A,B.

Example 2

players = ["A","B","C"]roomCount = 2operations = ["ADVANCE A","ADVANCE B","LEADERBOARD 3"]return = ["1","1","A,B,C"]

A entered room 1 before B, so that tie keeps A first. C follows from room 0.

Example 3

players = ["x","y"]roomCount = 1operations = ["GET y","LEADERBOARD 1","LEADERBOARD 0"]return = ["0","x",""]

Both players remain in room 0, where the original player order breaks the tie. A request for zero players returns an empty string.

Constraints

  • 1 <= players.length <= 100000
  • 1 <= roomCount <= 100000
  • 0 <= operations.length <= 200000
  • Player identifiers are unique nonempty ASCII strings without spaces or commas.
  • Every player referenced by an operation exists.
  • Every ADVANCE operation is valid.
  • 0 <= k <= players.length for every LEADERBOARD operation.

More Pinterest problems

  • Gaussian Naive Bayes Classifier (Machine Learning OA)OA · Seen Nov 2026
  • Top K Pins with Insert and QueryPHONE SCREEN · Seen Nov 2026
  • Pins Violation Log QueriesPHONE SCREEN · Seen Nov 2026
All Pinterest interview questionsSee Pinterest hiring insights
Saved
class Solution {
    public String[] runEscapeRoomLeaderboard(String[] players, int roomCount, String[] operations) {
      // write your code here
    }
}
Checking account…