FastPrepEvaluate a Flat Expression or Report Invalid Input
Problems/Evaluate a Flat Expression or Report Invalid Input

Evaluate a Flat Expression or Report Invalid Input

Meta logoMeta● MediumFULLTIMEPHONE SCREEN

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Meta MLE phone-screen report asks for a function to evaluate an expression such as 10/2+1*3+5, without parentheses, and says input can be invalid. The author explicitly discusses multiplication and division taking precedence. This practice supplies the omitted grammar, subtraction, truncating integer division, and exact ERROR result. Approximate source match: 76%.

Evaluate a flat arithmetic expression with nonnegative decimal integer operands and binary operators +, -, *, and /. Multiplication and division take precedence over addition and subtraction; operators at the same precedence are evaluated left to right. There are no parentheses or unary signs.

ASCII spaces may appear before, after, or between complete tokens, but not inside a number. Leading zeros are allowed. Divide integers by truncating toward zero. Return the decimal result as a string.

Return the exact string ERROR if the expression is empty or malformed, contains an unsupported character, has an operand larger than 10^6, or divides by zero. Examples of malformed syntax include adjacent operators, a missing operand, an unexpected parenthesis, and two numbers with no operator between them.

Function

evaluateFlatExpression(expression: String) → String

Examples

Example 1

expression = "10/2+1*3+5"return = "13"

Evaluate division and multiplication first: 5 + 3 + 5 = 13.

Example 2

expression = "20-7/2*3"return = "11"

7/2 truncates to 3, then 3*3 = 9, so the result is 11.

Example 3

expression = "1+*2"return = "ERROR"

The addition operator lacks a number on its right, so the syntax is invalid.

Constraints

  • 0 <= expression.length <= 100.
  • Valid operands are decimal integers from 0 through 10^6.
  • For valid arithmetic, every intermediate value and the final result fit a signed 64-bit integer.
  • Only ASCII spaces are allowed as whitespace.

More Meta Phone Screen questions

  • Convert a Sorted Linked List to a Balanced BSTPHONE SCREEN · Seen Nov 2026
  • Fuzzy Word Lookup With One Misspelled LetterPHONE SCREEN · Seen Nov 2026
  • Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Time to Buy and Sell StockPHONE SCREEN · Seen Nov 2026
  • First Element Greater Than KPHONE SCREEN · Seen Nov 2026
  • Count Events in Rolling Minute WindowsPHONE SCREEN · Seen Oct 2026
  • Valid Word AbbreviationPHONE SCREEN · Seen Oct 2026
  • Shortest Path in a Binary MatrixPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Evaluate an Arithmetic Expression Written in WordsBrex · PHONE SCREEN
  • Strict Text to Integer for a Given SizeAdobe · PHONE SCREENAdobe interview questions
  • Evaluate an Arithmetic ExpressionAkuna Capital · PHONE SCREENAkuna Capital interview questions
  • Solve a Linear Equation in xNutanix · PHONE SCREENNutanix interview questions
  • Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesStripe · PHONE SCREENStripe interview questions
  • Stack Formula InterpreterTypeSafe AI · PHONE SCREEN
  • Parse, Normalize, and Combine PolynomialsSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
  • Polynomial CoefficientsShopify · OAShopify interview questions
  • Calculate a Token-List ExpressionCollege Vine · ONSITE INTERVIEW
  • Simplify a Quadratic ExpressionOpenAI · OAOpenAI interview questions

Meta interview experiences

  • Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
  • Meta Business Support Engineer Phone Screen: 1 Experience
  • Meta Software Engineer Onsite Questions: 3 Experiences
  • Meta AI Native Engineer OA and Onsite: 1 Experience
  • Meta AI-Native Coding Interview: 3 Experiences
  • Meta Production Engineer Intern Questions: 6 Experiences
All Meta interview questionsSee Meta hiring insights
Saved
class Solution {
    public String evaluateFlatExpression(String expression) {
        // Write your code here.
    }
}
Checking account…