Practice Dinner Plate Stacks
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
DinnerPlates(capacity) maintains numbered stacks with equal capacity. push(val) uses the leftmost nonfull stack. pop() removes from the rightmost nonempty stack, returning -1 if all are empty. popAtStack(index) removes that stack's top or returns -1 when empty. Other stacks retain their indices. Practice approach: Track nonfull and nonempty stack indices with ordered sets or heaps and discard stale entries. Every removal creates insertion space, including holes in the middle. Trim empty trailing stacks carefully without shifting interior indices. Test refilling a hole before extending the row.
Source: Dinner Plate Stacks on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
["DinnerPlates","push","push","push","popAtStack","push","pop","pop","pop","pop"] [[2],[4],[7],[9],[0],[6],[],[],[],[]]
[null,null,null,null,7,null,9,6,4,-1]
Removing 7 creates room in stack zero; 6 refills it. pop still removes 9 from the rightmost stack first.
Constraints
Related LeetCode Problems
Practice more problems similar to Dinner Plate Stacks.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.