Positive-Integer Expression Evaluation
Updated
Problem statement
Evaluate an arithmetic expression containing positive-integer literals, parentheses, and +, -, *, and /.
Every intermediate result must remain a positive integer. Immediately reject the expression if subtraction produces zero or a negative value, or if division has a nonzero remainder. A later operation cannot rescue an invalid intermediate result.
For this exercise, use ordinary arithmetic precedence: parentheses first, then multiplication and division, then addition and subtraction. Operators with equal precedence are left-associative. There are no unary operators, and spaces between tokens may be ignored. The expression is syntactically valid.
Return the final positive result as a decimal string, or the exact string "False" when an intermediate result is invalid. Implement the expression splitting or parsing within your solution; no external parsing helper is needed.
Function
evaluateExpression(expression: String) → StringExamples
Example 1
expression = "(3 + (3 * 5)) / 2"return = "9"Compute 3 * 5 = 15, then 3 + 15 = 18, then 18 / 2 = 9. Every intermediate value is a positive integer.
Example 2
expression = "((3 - 5) + 12) / 2"return = "False"The first subtraction produces -2. Reject immediately, even though completing ordinary arithmetic would yield a positive integer.
Example 3
expression = "8 / 12"return = "False"The division does not produce an integer.
Constraints
- For this exercise, assume
1 <= expression.length <= 500. - Every literal is an integer in
[1,10^6]with no leading zero. - Input uses decimal digits, the four operators, parentheses and ASCII spaces.
- Every positive intermediate arithmetic result is at most
10^9; use signed 64-bit arithmetic for multiplication before validation.
More Jane Street Phone Screen questions
- Maximum-Scoring Consecutive Tree LevelsPHONE SCREEN · Seen Nov 2026
- Tree Selection and VisibilityPHONE SCREEN · Seen Nov 2026
- Load/Store Arithmetic InterpreterPHONE SCREEN · Seen Oct 2026
- Instrument Stack Language JumpsPHONE SCREEN · Seen Oct 2026
- Run a Stack Language InterpreterPHONE SCREEN · Seen Oct 2026
- Add Two Integers Given as StringsPHONE SCREEN · Seen Sep 2026
- Angle Between Clock HandsPHONE SCREEN · Seen Jul 2026
- Route Length From Two CyclistsPHONE SCREEN · Seen Jul 2026
- Sort TradesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Painted Cube: Count and RollPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Remove Parentheses from a Plus-Minus ExpressionOracle · PHONE SCREENOracle interview questions
- Parse Nested Message TypesApplied Intuition · PHONE SCREENApplied Intuition interview questions
- Decode StringCompass International Holdings · PHONE SCREENCompass International Holdings interview questions
- Calculator with ParenthesesGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Recursive Nested JSON Key SearchMongoDB · PHONE SCREENMongoDB interview questions
- Flatten JSON With Array IndicesAdobe · PHONE SCREENAdobe interview questions
- Decode StringSambaNova Systems · PHONE SCREENSambaNova Systems interview questions
- Plus and Minus CalculatorIndeed · PHONE SCREENIndeed interview questions
- Arithmetic Expression EvaluatorMicrosoft · PHONE SCREENMicrosoft interview questions
- Toy Language Generic Return-Type InferenceOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
Jane Street interview experiences
- Jane Street TDO UK and Hong Kong: 22 Experiences (Part 10 of 10)
- Jane Street TDOE US Final Round: 11 Experiences (Part 5 of 10)
- Jane Street TDO Phone Math Round: 26 Experiences (Part 9 of 10)
- Jane Street TDOE UK Phone Screen: 15 Experiences (Part 4 of 10)
- Jane Street TDO Excel and VBA Test: 23 Experiences (Part 8 of 10)
- Jane Street TDOE UK Coding Round: 15 Experiences (Part 3 of 10)