Evaluate dependent variable expressions
InstacartSoftware Engineer · OnsiteLast updated
This question evaluates a candidate's ability to parse and evaluate assignment expressions, resolve inter-variable dependencies, and detect cycles or unsolvable references.
Question
Given a target variable name and a list of assignment strings of the form 'Ti = expression' where the expression is either a number, a single variable, or arithmetic (+, −) over variables/numbers, compute the numeric value of the target variable. Extend to handle expressions that reference other variables recursively; detect cycles or unsolvable references and report an error.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.