Evaluate a Parenthesized Integer Expression
Updated
Problem statement
Evaluate the integer expression in expression.
The expression contains non-negative decimal integers, the binary operators + and -, parentheses, and spaces. A + or - may also appear as a unary sign, including immediately before a parenthesized expression.
Use integer arithmetic and return the value of the complete expression. Do not call a language-provided expression evaluator.
Function
calculate(expression: String) → intExamples
Example 1
expression = "1 + 1"return = 2Adding the two operands gives 2.
Example 2
expression = "(1+(4+5+2)-3)+(6+8)"return = 23The two outer groups evaluate to 9 and 14.
Example 3
expression = "-(2 + 3) + 10"return = 5The unary minus negates the parenthesized value 5.
Constraints
1 <= expression.length <= 100000expressionis a valid expression containing digits, spaces,+,-,(, and).- Every intermediate value and the final answer fit in a signed 32-bit integer.
Source note: The source image is a source-neutral excerpt of the author-reported prompt.
More Adobe Phone Screen questions
- 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
- All Safe Boards for N QueensPHONE SCREEN · Seen Jun 2026
Similar questions at other companies
- Parse Boolean Rule ExpressionsStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
- Arithmetic Expression EvaluatorMicrosoft · PHONE SCREENMicrosoft interview questions
- Arithmetic Expression CalculatorSnowflake · PHONE SCREENSnowflake interview questions
- Most Frequent Call Path From Function Trace LogsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Remove Parentheses from a Plus-Minus ExpressionOracle · PHONE SCREENOracle interview questions
- Stack Formula InterpreterTypeSafe AI · PHONE SCREEN
- Decode StringCompass International Holdings · PHONE SCREENCompass International Holdings interview questions
- Rich Text Parser Part 3 (Depth Tokens)Figma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
- Calculator with ParenthesesGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Decode an Encoded StringAmazon · PHONE SCREEN · ONSITE INTERVIEW
Interview reports that mention this question
Adobe interview experiences
- Adobe New Grad OA: Unit Conversion and Code Review: 1 Experience
- 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