FastPrepAdd and Subtract With Undo and Redo
Problems/Add and Subtract With Undo and Redo

Add and Subtract With Undo and Redo

Adobe logoAdobe● EasyINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem runs a calculator that adds to and subtracts from a running total and can undo and redo those steps. It returns the total after every operation. An Adobe software intern entry from Bengaluru (a copy of a review, August 2024) names writing such a calculator, with undo and redo, as its coding question. Other questions were on the candidate's projects and on database and operating-system basics. The entry gives no rules for undo and redo, no interface and no examples.

Our choices: the total starts at 0. Operations come as two arrays, and the total is returned after each one. Undo or redo with nothing to act on does nothing. A new add or subtract clears the redo history. A redone step can be undone again. Values are 0 to 10^9 with at most 2000 operations, so totals need 64 bits. The examples are new.

Our version is about 70% the same as the reported question.

A calculator keeps a running total that starts at 0. It supports four operations:

  • add v: add v to the total.
  • subtract v: subtract v from the total.
  • undo: take back the latest add or subtract that has not been taken back yet. If there is none, nothing happens.
  • redo: bring back the step that was taken back most recently. If there is none, nothing happens.

A new add or subtract ends the redo history: steps undone before it can no longer be redone. A step that was redone can be undone again.

Operation i is operations[i] with value values[i]. Return the total after each operation, in order. The total can be negative and can be larger than a 32-bit integer.

Function

runCalculator(operations: String[], values: int[]) → long[]

Examples

Example 1

operations = ["add","add","undo","subtract","redo","undo","undo"]values = [5,3,0,2,0,0,0]return = [5,8,5,3,3,5,0]

Totals: add 5 gives 5, add 3 gives 8, undo takes back the 3 (5). Subtract 2 gives 3 and also wipes out the undone add 3, so redo has nothing to redo (3). The two undos take back the subtract (5) and then the add 5 (0).

Example 2

operations = ["undo","redo","add"]values = [0,0,4]return = [0,0,4]

With nothing done yet, undo and redo change nothing and the total stays 0. Then add 4 gives 4.

Example 3

operations = ["add","subtract","undo","undo","redo","redo","redo"]values = [10,4,0,0,0,0,0]return = [10,6,10,0,10,6,6]

10, then 6. Two undos go back to 10 and then 0. Two redos bring back the add (10) and the subtract (6). The third redo has nothing left to redo, so the total stays 6.

Constraints

  • 1 <= operations.length <= 2000 and values.length == operations.length
  • Each operations[i] is "add", "subtract", "undo" or "redo"
  • 0 <= values[i] <= 10^9 for "add" and "subtract"; values[i] == 0 for "undo" and "redo"

More Adobe Phone Screen questions

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
  • Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
  • Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
  • Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
  • Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
  • Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • Implement a Queue Using Two StacksOracle · PHONE SCREENOracle interview questions
  • 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
  • Stack with Constant-Time Middle QueriesAmazon · PHONE SCREEN
  • Nested Recipe Cart TransactionsDecagon · PHONE SCREENDecagon interview questions
  • Text Editor, Part 2: Undo and RedoOpenAI · PHONE SCREENOpenAI interview questions
  • Text Document HistoryNotion · PHONE SCREEN · ONSITE INTERVIEWNotion interview questions
  • Key-Value Store with Nested TransactionsRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Code Editor FoldingJane Street · ONSITE INTERVIEWJane Street interview questions

Interview reports that mention this question

  • Adobe SWE Intern Interviews: 27 Experiences (Part 2 of 4)
  • Adobe Intern Interview Questions: 54 Experiences (Part 1 of 4)

Adobe interview experiences

  • Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
  • Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
  • Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
  • Adobe New Grad MTS Interview Questions: 7 Experiences
All Adobe interview questionsSee Adobe hiring insights
Saved
class Solution {
    public long[] runCalculator(String[] operations, int[] values) {
        // Write your code here.
    }
}
Checking account…