Super Stack With Bottom Increments
Updated
Problem statement
Start with an empty stack of integers and run operations in order. Each operation is one of:
"push v": put the integervon top."pop": take the top element off. This never comes while the stack has no elements."inc k d": adddto each of thekelements nearest the bottom. If the stack holds fewer thankelements, adddto all of them.
After every operation, record the top element as a decimal string, or "EMPTY" if the stack is empty. Return the recorded strings in order.
Function
superStack(operations: String[]) → String[]Examples
Example 1
operations = ["push 6","push -2","inc 1 10","pop","inc 5 -1","push 3","pop","pop"]return = ["6","-2","-2","16","15","3","15","EMPTY"]inc 1 10 touches just the lowest element, turning 6 into 16, so the top is still -2. After the pop, 16 is on top. inc 5 -1 asks for 5 elements but there is only one, so it changes that one to 15. 3 is pushed and popped, and the last pop empties the stack.
Example 2
operations = ["push 0","pop"]return = ["0","EMPTY"]After the push the top is 0; after the pop nothing is left, so the answer is "EMPTY".
Example 3
operations = ["push 2","inc 1 4","push 8","push 5","inc 2 -1","pop","pop"]return = ["2","6","8","5","5","7","5"]With one element, inc 1 4 reaches the top and turns 2 into 6. After 8 and 5 are pushed, inc 2 -1 lowers the two lowest elements to 5 and 7 and leaves 5 on top alone. The two pops uncover 7 and then 5.
Constraints
1 <= operations.length <= 2000- Each operation is
"push v","pop"or"inc k d", with single spaces and plain decimal integers. -10^4 <= v, d <= 10^4and1 <= k <= 2000"pop"is only given when the stack is not empty.
More Capital One Onsite Interview questions
- Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
- Sort ColorsONSITE INTERVIEW · Seen Oct 2026
- Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
- Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
- Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
- Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
- Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
- Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
- Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025
Similar questions at other companies
- Code Editor FoldingJane Street · ONSITE INTERVIEWJane Street interview questions
- Undo and Redo Command HistoryNetflix · ONSITE INTERVIEWNetflix interview questions
- Text Document HistoryNotion · PHONE SCREEN · ONSITE INTERVIEWNotion interview questions
- Transactional In-Memory RedisHashiCorp · ONSITE INTERVIEWHashiCorp interview questions
- Key-Value Store with Nested TransactionsRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Implement a Queue Using Two StacksAmazon · ONSITE INTERVIEW
- Billing Log with Undo and RedoReddit · PHONE SCREENReddit interview questions
- Multiline Text Editor with Cursor MovementDatologyAI · PHONE SCREEN
- Layer History with Batch Undo and RedoFigma · OA · PHONE SCREENFigma interview questions
- Undo/Redo Timeline State EngineKickdrum · OA
Capital One interview experiences
- Capital One Coding OA Questions: 3 Experiences
- Capital One Experienced Engineer Power Day and OA: 6 Experiences
- Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
- Capital One TDP Agentic Round (AI Coding): 7 Experiences
- Capital One SWE Power Day, Level Not Reported: 6 Experiences
- Capital One TIP Intern OA and Power Day: 13 Experiences