Back to problems

Evaluate Symbols in an Expression Map (with Cycle Detection)

Algorithm · Harvey · Medium

You are given an expression map: a dictionary where each key is a symbol and its value is a string representing an expression. An expression can contain: integer constants references to other symbols (keys present in the same map) binary operators such as +, -, *, / The final value of a symbol is computed by evaluating its expression, recursively resolving any referenced symbols first. Return a dictionary mapping every symbol to its final integer value. Follow-up If the…

Checking your access…