Basic Calculator II

Medium · Stack & Monotonic Stack · about 25 minutes

Asked at Meta, Amazon, Microsoft, Airbnb.

s is a well-formed arithmetic expression made of non-negative integers, the operators + - * / and spaces, with no parentheses. Compute its value, applying * and / before + and -. Division drops any fractional part (rounds toward zero). Do the parsing yourself instead of calling eval.