Code RoomMax size stack increment
MediumPrep Room Coding #919

Max size stack increment

CodingAlgorithms & data structuresMid–Senior~20 min

Design a stack with a maximum size that also supports a bulk increment. Process ops: ['push', x] pushes x only if the stack has fewer than maxSize elements (otherwise no-op); ['pop'] removes and returns the top, or -1 if empty; ['increment', k, val] adds val to the bottom-most k elements (or all elements if there are fewer than k). Return the list of pop results, in order.

Implement
custom_stack(maxSize: int, ops: list[list]) → list[int]
Examples
in[3,[["push",1],["push",2],["pop"],["push",2],["push",3],["push",4],["increment",5,100],["increment",2,100],["pop"],["pop"],["pop"],["pop"]]]out[2,103,202,201,-1]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 20 min
InputExpectedGot
[3,[["push",1],["push",2],["pop"],["push",2],["push",3],["push",4],["increment",5,100],["increment",2,100],["pop"],["pop"],["pop"],["pop"]]][2,103,202,201,-1]not run yetsample