Tessian policy evaluation may represent arithmetic rules as prefix expressions. Given a valid prefix expression and an inclusive integer range for every variable, return the maximum value the expression can produce.
The expression contains lowercase single-character variables and binary operators +, -, and *. Each variable appears exactly once. Variables are independent, so any allowed value may be selected for each one.
Implement maximize_expression(expression, ranges).
expression is a non-empty string in prefix notation, with no spaces.ranges is a dictionary mapping each variable to a two-element list [low, high].For a subtree, track both its minimum and maximum possible values. This is necessary because subtraction and multiplication may use a subtree's minimum when maximizing a parent expression.
def maximize_expression(expression, ranges):