FastPrepEvaluate Parenthesized Addition and Subtraction
Problems/Evaluate Parenthesized Addition and Subtraction

Evaluate Parenthesized Addition and Subtraction

Atlassian logoAtlassian● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Atlassian full-time phone screen. The report names the Basic Calculator family, and our version is about 80% the same. The report has no actual sample expressions. We chose these: how plus and minus group, the rules for a unary minus, spaces, decimal zeros, and the input limits. We wrote all the examples.

You are given a valid math expression as a string. It uses whole numbers, +, - and parentheses. Work out its value and return it as an integer.

Here is what the expression can contain:

  • A factor is either a nonnegative number written in decimal, or an expression inside parentheses.
  • An expression is one factor, followed by zero or more pairs. Each pair is a + or - sign, then another factor.
  • Either kind of factor may have one minus sign in front of it, which makes it negative.
  • ASCII spaces may appear between the parts (numbers, signs and parentheses).
  • A number may have leading zeroes. Still read it as a normal decimal number.

The input is always valid and never empty. You do not need to handle multiplication, division, a plus sign used to mark a positive number, or invalid input.

The expression is at most 500 characters long, and parentheses nest at most 50 levels deep. Each number is from 0 through 1000000. Every partial result and the final answer fit in a signed 32-bit integer.

Function

evaluateParenthesized(expression: String) → int

Examples

Example 1

expression = "8-(3-2)"return = 7

Work out the parentheses first: three minus two is one. Then eight minus one is 7.

Example 2

expression = "-(2+3)+10"return = 5

Inside the parentheses, two plus three is five. The minus sign in front makes it negative five. Adding ten gives 5.

Example 3

expression = "1-(-2)+4"return = 7

Inside the parentheses, the minus sign makes two negative. One minus negative two is three. Adding four gives 7.

Constraints

  • 1 <= expression.length <= 500, and parentheses nest at most 50 levels deep.
  • Every number is from 0 through 1000000. Every partial result and the final result fit in a signed 32-bit integer.
  • The expression only follows the rules in the statement: decimal numbers, plus and minus between factors, parentheses, a minus sign in front of a factor, and spaces between parts.

More Atlassian Phone Screen questions

  • Merge Overlapping IntervalsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Tennis Court SchedulingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Implement a Rate LimiterPHONE SCREEN · Seen Oct 2026
  • Longest Consistent Activity StreakPHONE SCREEN · Seen Sep 2026
  • Music Player Operation SequencePHONE SCREEN · Seen Sep 2026
  • Underline Shortest Unique SubstringsPHONE SCREEN · Seen Aug 2026
  • Can a Dictionary Word Be Formed from Note Letters?PHONE SCREEN · Seen Feb 2026
  • Word Path Moving Only Right or DownPHONE SCREEN · Seen Feb 2026
  • Ordered Badge Entry and Exit ViolationsPHONE SCREEN · Seen Aug 2025
  • Two Sum with an Ordered Index PairPHONE SCREEN · Seen Aug 2025

Similar questions at other companies

  • Basic Calculator IISnap Inc. · PHONE SCREENSnap Inc. interview questions
  • Simplify a Nested Variable ExpressionGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Evaluate Arithmetic with Operator PrecedenceRoblox · PHONE SCREENRoblox interview questions
  • Simplify a Formula with Known and Unknown VariablesBetter.com · PHONE SCREEN
  • Stack Formula InterpreterTypeSafe AI · PHONE SCREEN
  • Calculate a Token-List ExpressionCollege Vine · ONSITE INTERVIEW
  • Adjacent Equal-Pair Removal GameZipRecruiter · OAZipRecruiter interview questions
  • Smallest Value for a Linear Expression ModuloIntel · OA
  • Adjacent Pair and Run RemovalWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • Evaluate an Arithmetic Expression Written in WordsBrex · PHONE SCREEN

Atlassian interview experiences

  • Atlassian MLE Phone Screen: Model Deployment Design: 1 Experience
  • Atlassian Coding Screens and Karat: 3 Experiences (Part 2 of 2)
  • Atlassian Full Stack Interviews: 11 Experiences (Part 1 of 2)
All Atlassian interview questionsSee Atlassian hiring insights
Saved
class Solution {
    public int evaluateParenthesized(String expression) {
        // Write your code here.
        return 0;
    }
}
Checking account…