FastPrepEvaluate Arithmetic with Operator Precedence
Problems/Evaluate Arithmetic with Operator Precedence

Evaluate Arithmetic with Operator Precedence

Roblox logoRoblox● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The named Basic Calculator II family matches at about 80%. The reports give no literal expressions or full grammar. We chose four operators, precedence, associativity, division that truncates, rules for valid input, and the limits. All examples are ours. Our version is about 80% the same as the reported question.

Evaluate a valid integer expression containing binary +, -, * and /, and return its integer value.

For this exercise, assume input is a nonnegative decimal literal followed by zero or more operator/literal pairs. Do multiplication and division before addition and subtraction. Within each of these two groups, work from left to right. After division, discard the fractional part, rounding toward zero. ASCII spaces may occur between tokens, and leading zeroes are decimal. Parentheses, unary signs and invalid-input handling are outside this contract.

For this exercise, assume length at most 500, literals from 0 through 1000000, nonzero divisors, and signed 32-bit arithmetic intermediates/final results.

Function

evaluateWithPrecedence(expression: String) → int

Examples

Example 1

expression = "3+2*2"return = 7

Multiply first, so the result is 7.

Example 2

expression = "14-7/2"return = 11

Truncate 7/2 to 3 before subtraction, giving 11.

Example 3

expression = "20/3/2"return = 3

Divide from left to right: 20/3 is 6 and 6/2 is 3.

Constraints

  • For this exercise, assume 1 <= expression.length <= 500.
  • Every literal is an integer from 0 through 1000000.
  • Input is always valid under the stated flat four-operator grammar and every divisor is nonzero.
  • All arithmetic intermediates and the final result fit signed 32-bit integers.

More Roblox Phone Screen questions

  • Most Frequent Call Path From Function Trace LogsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Design Search Autocomplete SystemPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Candy Crush Grid Matching and GravityPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Implement a Rate LimiterPHONE SCREEN · Seen Oct 2026
  • Rate Limit by Multiple Request FieldsPHONE SCREEN · Seen Oct 2026
  • Topological Sort with Secondary OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Time-Aware Search AutocompletePHONE SCREEN · Seen Oct 2026
  • Most Frequent Call Stack Per ThreadPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Rate Limiter Sliding Window With Per-Entity LimitsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Closest Binary Search Tree Value — Base PracticePHONE SCREEN · Seen Jun 2026

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
  • Simplify a Formula with Known and Unknown VariablesBetter.com · PHONE SCREEN
  • Evaluate Parenthesized Addition and SubtractionAtlassian · PHONE SCREENAtlassian interview questions
  • 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

Roblox interview experiences

  • Roblox OA: What It Tests (2026)
  • Roblox New Grad Early OA Tasks: 10 Experiences (Part 7 of 7)
  • Roblox New Grad Engineer Rounds: 13 Experiences (Part 6 of 7)
  • Roblox New Grad HackerRank OA: 18 Experiences (Part 5 of 7)
  • Roblox New Grad CodeSignal Finals: 23 Experiences (Part 4 of 7)
  • Roblox New Grad Games and BQ: 25 Experiences (Part 3 of 7)
All Roblox interview questionsSee Roblox hiring insights
Saved
class Solution {
    public int evaluateWithPrecedence(String expression) {
        // Write your code here.
        return 0;
    }
}
Checking account…