FastPrepAdding Stack 2.0
Problems/Adding Stack 2.0

Adding Stack 2.0

IMC Trading logoIMC Trading● MediumINTERNNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an IMC Trading online assessment. The report describes the constant-time sum requirement in two ways. This version returns the current sum after every operation. Our version is about 96% the same as the reported question.

Process a sequence of operations on a stack that starts empty. The stack supports these commands:

  • push v: push integer v.
  • pop: remove the top element.
  • inc i v: add v to each of the bottom i elements.

Return an array whose kth value is the sum of all values in the stack after the kth command. The sum of an empty stack is 0.

Every operation and every reported sum must be processed in O(1) time.

Function

processAddingStack(operations: String[]) → long[]

Examples

Example 1

operations = ["push 4","push 5","inc 2 1","pop","pop"]return = [4,9,11,5,0]

The first two sums are 4 and 9. The increment changes the stack to [5, 6] with sum 11; the two pops then leave sums 5 and 0.

Example 2

operations = ["push 1","push 2","inc 1 10","pop"]return = [1,3,13,11]

Incrementing only the bottom value changes [1, 2] to [11, 2], whose sum is 13. Popping 2 leaves a sum of 11.

Constraints

  • 1 <= operations.length <= 2 * 10^5
  • -10^9 <= v <= 10^9
  • For every inc i v, 1 <= i <= current stack size.
  • A pop command is issued only when the stack is nonempty.
  • Every command has exactly one of the three forms described above.
  • Every stack value and reported sum fits in a signed 64-bit integer.

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

  • Billing Log with Undo and RedoReddit · PHONE SCREENReddit interview questions
  • Stack with Constant-Time Middle QueriesAmazon · PHONE SCREEN
  • Bank Accounts with Balance HistoryMeta · OAMeta interview questions
  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Process Banking OperationsVercel · OA
  • Layer History with Batch Undo and RedoFigma · OA · PHONE SCREENFigma interview questions
  • Asteroid CollisionMicrosoft · OAMicrosoft interview questions
  • Undo/Redo Timeline State EngineKickdrum · OA
  • Memory AllocatorTikTok · OATikTok interview questions
  • Integer Map Using a VectorAdobe · OAAdobe interview questions

Interview reports that mention this question

  • IMC Trading OA: What It Tests (2026)
  • IMC Trading SWE OA and Video: 18 Experiences (Part 3 of 3)
  • IMC Trading SWE OA Questions: 22 Experiences (Part 2 of 3)
  • IMC SWE New Grad OA and Interviews: 58 Experiences (Part 1 of 3)
All IMC Trading interview questionsSee IMC Trading hiring insights
Saved
class Solution {
    public long[] processAddingStack(String[] operations) {
        // Write your code here.
        return new long[0];
    }
}
Checking account…