As reported: Walmart SWE-III (IN3) DSA round (Jul 2025), third question: LeetCode Basic Calculator III. A stack-based approach was explained but the code was not completed in time.
Given a valid expression string s with non-negative integers, +, -, *, /, parentheses and spaces, evaluate it. Integer division truncates toward zero. Do not use a built-in eval.
This is LeetCode 772 — Basic Calculator III.
Example
"1+1" -> 2
"6-4/2" -> 4
"2*(5+5*2)/3+(6/2+8)" -> 21
Constraints: 1 ≤ s.length ≤ 10^4; the expression is valid; all intermediate results fit in a signed 32-bit integer.
Code runner format: one line with s as a JSON string. Implement calculate(s); the harness prints the value.