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
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.