Given an algebraic expression represented by the string expression, along with two arrays evalvars and evalints representing known variable assignments where evalvars[i] is assigned the integer value evalints[i], evaluate and simplify the expression to a canonical polynomial representation.
The canonical representation of a polynomial is a list of strings representing non zero terms sorted according to the following rules:
Terms are ordered in descending order by their degree, where the degree of a term is the total number of variable factors it contains.
Terms with the same degree are ordered in lexicographical order based on their variable names.
Each term with degree greater than '*', with variables sorted in lexicographical order (for example, "2*a*b*c" or "-1*a*a").
Terms with degree "14" or "-64").
Terms with a coefficient of
The expressions follow standard operator precedence, where multiplication takes precedence over addition and subtraction, and subexpressions enclosed in parentheses are evaluated first.
Constraints:
expression.length
expression consists of lowercase English letters, digits, '+', '-', '*', '(', ')', and ' '.
expression does not contain any leading or trailing spaces.
All tokens in expression are separated by a single space.
evalvars.length
evalvars[i].length
evalvars[i] consists of lowercase English letters.
evalints.length evalvars.length
evalints[i]
Given an algebraic expression represented by the string expression, along with two arrays evalvars and evalints representing known variable assignments where evalvars[i] is assigned the integer value evalints[i], evaluate and simplify the expression to a canonical polynomial representation.
The canonical representation of a polynomial is a list of strings representing non zero terms sorted according to the following rules:
Terms are ordered in descending order by their degree, where the degree of a term is the total number of variable factors it contains.
Terms with the same degree are ordered in lexicographical order based on their variable names.
Each term with degree greater than '*', with variables sorted in lexicographical order (for example, "2*a*b*c" or "-1*a*a").
Terms with degree "14" or "-64").
Terms with a coefficient of
The expressions follow standard operator precedence, where multiplication takes precedence over addition and subtraction, and subexpressions enclosed in parentheses are evaluated first.
Constraints:
expression.length
expression consists of lowercase English letters, digits, '+', '-', '*', '(', ')', and ' '.
expression does not contain any leading or trailing spaces.
All tokens in expression are separated by a single space.
evalvars.length
evalvars[i].length
evalvars[i] consists of lowercase English letters.
evalints.length evalvars.length
evalints[i]