Code Room
CodingMediumcod-g231
Subject Expression evaluationLevel Mid–Senior~30 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

Evaluate a boolean expression string built from the literals 'T' and 'F', the binary operators '&' (and) and '|' (or), the unary prefix '!' (not), and parentheses. Precedence from highest to lowest: '!' , then '&', then '|'. '&' and '|' are left-associative; '!' may stack (e.g. '!!T'). There may be spaces between tokens. The expression is always valid. Return a bool. Examples: 'T & F' -> False, '!F | F' -> True, '!(T & F)' -> True.

Implement
eval_bool(expr: str) → bool
Examples
in["T & F"]outfalse
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.