Evaluate a Flat Addition and Subtraction Expression
Updated
Problem statement
Given expression, evaluate its decimal integer additions and subtractions from left to right and return the integer result.
For this exercise, assume the expression is valid and nonempty: it starts with an unsigned integer and may continue with + or - followed by another unsigned integer. ASCII spaces may occur between tokens, and leading zeroes are interpreted as decimal. Unary signs, parentheses, multiplication, division and invalid-input handling are outside the scope of this problem.
For this exercise, assume a length of at most 500, literals from 0 through 1000000, and all intermediate/final results within signed 32-bit range.
Function
evaluateFlat(expression: String) → intExamples
Example 1
expression = "3+2-4"return = 1Adding and subtracting from left to right, the expression evaluates to 1.
Example 2
expression = "10 - 20 + 3"return = -7The result is negative; spaces occur between tokens.
Example 3
expression = "005 + 12 - 0007"return = 10Leading zeroes are treated as decimal digits.
Constraints
- For this exercise, assume
1 <= expression.length <= 500. - Every literal is a decimal integer from
0through1000000. - Only binary plus/minus and optional ASCII spaces occur; input is always syntactically valid.
- All intermediate and final values fit a signed 32-bit integer.
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
- Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesStripe · PHONE SCREENStripe interview questions
- Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
- Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
- Stack Formula InterpreterTypeSafe AI · PHONE SCREEN
- Roman to IntegerKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Minimum Difference Between Two Clock TimesMicron Technology · PHONE SCREEN
- Decimal Digits in OrderZoomInfo · PHONE SCREEN
- Add Two Integers Given as StringsJane Street · PHONE SCREENJane Street interview questions
- Fizz and Buzz Words From 1 to nDocuSign · PHONE SCREENDocuSign interview questions
- Integer to String Without Built-insHudson River Trading · PHONE SCREENHudson River Trading interview questions