Boolean expression evaluation
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) → boolExamples
in
["T & F"]outfalseWhat 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
solution.py
InputExpectedGot
["T & F"]falsenot run yetsample