Basic Calculator III
Difficulty: Hard
Category: DSA
Topics: Math, String, Stack, Recursion
Asked at: Facebook, Amazon, ByteDance
You are given a string `s` representing a valid mathematical expression. The expression may contain non-negative integers, the operators `'+'`, `'-'`, `'*'`, `'/'`, parentheses `'('`, `')'`, and spaces.
Evaluate the expression and return its result as an integer.
Note that integer division should truncate toward zero. You are **not allowed** to use any built-in function that evaluates strings as mathematical expressions (such as `eval()`).
**Constraints:**
- `1 <= s.length <= 10^4`
- `s` consists of digits, operators `'+'`, `'-'`, `'*'`, `'/'`, parentheses `'('`, `')'`, and spaces.
- The given expression is always valid.
Return the integer result of evaluating the expression.