Design a Stack With Increment Operation
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
Design a bounded stack of integers that also supports adding a value to its **bottom** elements.
- CustomStack(maxSize) creates an empty stack that can hold at most maxSize elements.
- push(x) pushes x on top if the stack holds fewer than maxSize elements; otherwise it does nothing.
- pop() removes and returns the top element, or returns -1 if the stack is empty.
- increment(k, val) adds val to each of the bottom k elements. If the stack holds fewer than k elements, every element is incremented.
All three operations can be done in O(1).
Examples
Constraints
- `1 <= maxSize, x, k <= 1000`
- `0 <= val <= 100`
- At most 1000 calls to each method.
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.