Code Room
CodingMediumcod-g350
Subject Design data structuresLevel Mid–Senior~20 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.