Skip to content
Onsite

Masai Coding Competition

MediumP3Coding

Students from several clubs wait in one queue. When a new student arrives, they search from the end of the queue for a clubmate; if they find one, they stand directly behind that clubmate (the last clubmate in the queue), otherwise they stand at the very end.

You are given ops, processed in order. Each operation is one of:

  • ["E", club, roll]: a student of the given club with the given roll number arrives.
  • ["D"]: the student at the front of the queue leaves; report "<club> <roll>" for that student.

Return the reports in order. A ["D"] is only given when the queue is not empty.

Example 1

Input
ops = [["E","1","10"],["E","2","20"],["E","1","11"],["D"],["D"],["D"]]
Output
["1 10","1 11","2 20"]
Why
Student 11 of club 1 stands behind student 10, ahead of club 2.

Constraints

  • 1 <= ops.length <= 10^5
  • club and roll are positive integers given as strings
  • D is never given on an empty queue

Hints

Run checks the 3 visible tests, Submit all 8.