Basic Calculator II
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Evaluate the arithmetic expression in string s and return its integer value. The expression contains non-negative integer literals, the binary operators +, -, *, /, and spaces. There are no parentheses and no unary minus.
Use normal precedence: * and / bind tighter than + and -, and operators of equal precedence apply left to right. Integer division truncates toward zero.
Do not use a built-in expression evaluator such as eval. The input is always a valid expression, never divides by zero, and every intermediate result fits in a signed 32-bit integer.
Examples
Constraints
- 1 <= s.length <= 3 * 10^5
- s consists of digits, spaces, and '+', '-', '*', '/'
- every integer literal is in [0, 2^31 - 1]
- the answer fits in a signed 32-bit integer
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.