AO
Back

Basic Calculator II (Expression Evaluator)

CodingOnsiteLast reported August 2025Medium Frequency

Problem Overview

A calculator round reported four times at Snowflake: twice in phone screens and twice in onsite (VO) loops, from March to August 2025. Two reports name the problem: one candidate's phone screen was LeetCode 227 (Basic Calculator II), and an intern says one VO problem was LeetCode 227. A third candidate says only that they wrote an expression evaluator, and a fourth only that the round was a variant of a calculator problem; neither gives the rules. The 227 phone screen had a follow-up: what if a number is negative, as in 3+2*-2, with no parentheses. That candidate had confirmed at the start that the expression is valid, and argued with the interviewer that this input was not.

Part 1 — Basic Calculator II

LeetCode 227. Given a string s holding a valid expression of non-negative integers, the operators + - * / and spaces, return its value. * and / are applied before + and -; operators of the same precedence go left to right. Division is integer division that truncates toward zero. There are no parentheses, and you may not call eval. Examples: "3+2*2" is 7, " 3/2 " is 1, " 3+5 / 2 " is 5, and "1-7/2" is -2.

Part 2 — Negative numbers after an operator

The reported follow-up. A minus sign may now also be the sign of a number: at the very start of the expression, or right after another operator, with no parentheses. "3+2*-2" is 3 + (2 × -2) = -1, "-3+5" is 2 and "2--3" is 5. Everything from Part 1 still holds, including truncation toward zero ("-7/2" is -3). How to read the follow-up input is our reading; the report does not say what answer the interviewer expected.

What the tests call. calculate(s: str) -> int on both tabs, printing the integer it returns. The tests never divide by zero and never put a space between a sign and its number.

Follow-up Arc

Interviewers escalate through these phases. The order varies, but most candidates see at least one from each bucket.
Trade-off discussion · 1
Trade-off discussion

What if a number is negative, as in 3+2*-2, with no parentheses?

Probes for: After the base solution works

Approach Trade-offs

Approaches actually attempted in reports — including ones that lost candidates time. Pick deliberately.
ApproachNotes
Two stacks (operands and operators, shunting-yard)More code for LeetCode 227, but it extends directly to parentheses (LeetCode 224 / 772).
Running sum plus last termThe same pass with O(1) extra space instead of a stack.

What Reports Emphasize

Common mistakes: Floor division instead of truncation toward zero: 1-7/2 holds -7 on the stack, and -7 // 2 is -4, so the answer comes out -3 instead of -2.; Applying an operator when it is read instead of when its right operand is complete, or forgetting to flush the last number at the end of the string.

What passers do: Our recommendation: confirm at the start that the expression is always valid. One phone-screen candidate did, and could point back to it when the follow-up arrived.

Why people fail: One phone-screen candidate wrote the optimal solution with one wrong line, spent time debugging it, and believes that round failed them.

Edge cases probed: 3+2*-2: a negative number after an operator, with no parentheses (the interviewer's follow-up input)

Practice

Write your own against 11 test cases, or read the worked solution — approach, complexity, and code that runs.

Prepping for Snowflake with friends?

Send them this page. It is free to read, no account needed.

More Snowflake Questions

Free preview

Every question in the Snowflake catalog gets this depth

What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 86 Snowflake questions, refreshed monthly from new candidate reports.

$59/mo — or $50/mo with the 3-month pass · cancel anytime
Snowflake · Coding · Reported 4× across candidate reports
Is this helpful?