Loading
Loading
A monitoring stack must report the smallest value it currently holds, in constant time, alongside the usual push and pop.
The input is a list of operations encoded as integers: a value ≥ 0 means push that value, -1 means pop, and -2 means record the current minimum.
Return the recorded minimums in order.
ops = [5, 3, -2, -1, -2]push 5stack [5], min 5push 3stack [5,3], min 3queryrecord 3popstack [5], min back to 5queryrecord 5[3, 5]Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Example 2
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(1) per operation time · O(n) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.