Dinner Plate Stacks
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Picture an unbounded row of stacks numbered from 0 left to right, each holding at most capacity plates. Implement DinnerPlates(capacity):
- push(val) puts val on the **leftmost** stack that is not full (a new stack at the right end is used if all existing ones are full).
- pop() removes and returns the top plate of the **rightmost** non-empty stack, or -1 if every stack is empty.
- popAtStack(index) removes and returns the top plate of stack index, or -1 if that stack is empty or does not exist.
Popping from the middle can leave gaps; later pushes fill the leftmost gap first. Aim for O(log n) per operation.
Examples
Constraints
- 1 <= capacity <= 2 * 10^4
- 1 <= val <= 2 * 10^4
- 0 <= index <= 10^5
- At most 2 * 10^5 calls in total
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.