Spot the bug: pop returns the wrong value
Standard · Find the bug · about 8 min
This array stack passes its push and peek tests, but pop returns the wrong value. Click the line with the bug, then fix it. Results follow the same rules as "Implement a stack on an array".
Example 1
Input:
[3,["push 4","push 7","pop"]]
Output:
[1,1,7]
The buggy pop returns 4, the value under the top.
Constraints
- 1 ≤ capacity ≤ 1, 000
- 1 ≤ ops.length ≤ 1, 000
Learn the idea first: Stacks: push, pop, peek; array and linked implementations, a visual lesson.
More Stacks: push, pop, peek; array and linked implementations problems
- Overflow handling Warm-up
- State after a sequence Warm-up
- Implement a stack on an array Standard
- Baseball game score Standard
- Implement a stack with a linked list Challenge