Design a Stack With Increment Operation
Medium · Stack & Monotonic Stack · about 15 minutes
Asked at Amazon, Google, Microsoft.
Design a stack with a maximum size.
CustomStack(maxSize)creates it.push(x)pushesxif the stack has fewer thanmaxSizeelements.pop()pops and returns the top, or -1 if empty.increment(k, val)addsvalto the bottomkelements (all of them if fewer).