Medium · Stacks & Queues
Calculate Infix
Given a string exp holding a valid infix expression of non-negative integers, the binary operators +, -, * and /, and optional spaces (no parentheses), return its value: * and / bind tighter than + and -, equal-precedence operators apply left to right, and / is integer division.
Examples
Example 1
{
"exp": "2+3*4"
}Output: 14
Example 2
{
"exp": "10+2*6-3"
}Output: 19
Rebuild it in the studio
Core interview problems are free with a full runner and lessons; Pro opens the complete library.