Code RoomBoolean expression evaluation
MediumPrep Room Coding #805

Boolean expression evaluation

CodingAlgorithms & data structuresMid–Senior~30 min

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.

0:00 of about 30 min
InputExpectedGot
["T & F"]falsenot run yetsample