Back to problems

Evaluate Basic Expression Without Stack or Extra Space

Algorithm · Meta · Hard

Create a simple calculator that computes the result of an expression string with no parentheses and the operators +, -, *, and /. Do not rely on a stack, and use only O(1) extra space. Input: a string representing a mathematical expression; Output: the expression's integer result. Example The division is performed before addition, so 6 / 3 is 2, making the final value 8 + 2 = 10.

Checking your access…