Adding Stack with Top Values
Updated
Problem statement
Implement a stack that starts empty and processes the commands in operations:
push v: add integervto the top.pop: remove the top.inc i v: addvto each of the bottomielements.
Return one string per command: the current top as a decimal integer, or EMPTY if the stack is empty. Each command should take constant amortized time. Use signed 64-bit arithmetic for stack values.
Function
superStack(operations: String[]) → String[]Examples
Example 1
operations = ["push 4","push 5","inc 2 1","pop","pop"]return = ["4","5","6","5","EMPTY"]Report the current top after each operation, including EMPTY when the stack becomes empty.
Example 2
operations = ["push 2","push 8","inc 1 3","pop","push -1","pop","pop"]return = ["2","8","8","5","-1","5","EMPTY"]Report the current top after each operation, including EMPTY when the stack becomes empty.
Constraints
1 <= operations.length <= 2 * 10^5-10^9 <= v <= 10^9- For
inc i v,1 <= i <= current stack size. popis never called on an empty stack.
More IMC Trading Online Assessment questions
- Earliest Meeting Start on a 24-Hour ClockOA · Seen Nov 2026
- Grid Paths with Override PassesOA · Seen Oct 2026
- Weighted LFU CacheOA · Seen Sep 2026
- Rock JumpingOA · Seen Aug 2026
- Stack Batch RemovalOA · Seen Aug 2026
- Chain of CommandOA · Seen Aug 2026
- Choose ContainersOA · Seen Aug 2026
- Sub-matrix SumsOA · Seen Jul 2026
- Sub-matrix SumsOA · Seen Jul 2026
- Can Every Package Fit in a BoxOA · Seen Jul 2026
Similar questions at other companies
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Sum of Subarray MinimumsNVIDIA · OANVIDIA interview questions
- Shopkeeper Final Price SummaryMicrosoft · OAMicrosoft interview questions
- Nested Recipe Blocks (Game Adaptation)Roblox · OARoblox interview questions
- Maximum Capped Histogram Area After One RemovalMyntra · OAMyntra interview questions
- Steps to the Next Higher Value in a CircleRippling · OARippling interview questions
- Shopkeeper Final PriceUber · OAUber interview questions
- Predict AnswerAmazon · OA
- Retention Policy CollisionBox · OABox interview questions
- Longest Prefix-Valid Binary SubarrayHackerRank · OAHackerRank interview questions