Code Room
CodingHardcod-g451
Subject Expression evaluationLevel Senior–Staff~40 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

Evaluate an expression given as a list of tokens, where each token is either an integer (as a Python int) or one of the operator strings '+','-','*','/','^'. '^' is exponentiation and is RIGHT-associative; '*','/' are left-associative with precedence above '+','-'; '^' has the highest precedence. Division is integer division truncating toward zero and operands are positive enough that exponents are small (0..6). Use the shunting-yard algorithm. The token list is a valid infix expression with no parentheses. Return the integer result.

Implement
eval_infix(tokens: list) → int
Examples
in[[2,"+",3,"*",4]]out14
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.