def calculate(s: str) -> int:
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.
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.
Standard explanation — no candidate report records what the interviewer accepted here.
Reported: asked in a LeetCode 227 phone screen after the candidate had confirmed the expression is valid; the candidate argued this input was invalid, and the report does not say what answer the interviewer expected. Our answer: a minus at the start or right after another operator is the number's sign, so 3+2*-2 = 3 + (2 * -2) = -1; apply the sign before the pending * or /, and keep truncating toward zero.
From candidate reports: four reports from March to August 2025. One candidate's phone screen was LeetCode 227. They wrote the optimal solution, had one wrong line and spent time debugging it, and then got the follow-up about 3+2*-2 with no parentheses. Having confirmed at the start that the expression was valid, they argued the input was invalid, and they believe this interviewer failed them. An intern names LeetCode 227 as one of their two VO problems and got a hiring-manager call the same day. A third candidate wrote an expression evaluator in a VO they passed, and a fourth says only that a phone-screen round was a variant of a calculator problem.
A separate Snowflake round asks for a command interpreter (ADD 2, MULT 3, user-defined functions) that some candidates also call a calculator. That is the SnowCal problem, not this one.
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.
What if a number is negative, as in 3+2*-2, with no parentheses?
| Approach | Notes |
|---|---|
| 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 term | The same pass with O(1) extra space instead of a stack. |
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)
Send them this page. It is free to read, no account needed.
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.