Applied IntuitionCoding·45 minFree preview
Variable Expression Evaluation
Evaluate named arithmetic expressions whose variables can depend on definitions appearing later in the input. Extend the evaluator to distinguish unresolved variables from cyclic dependencies.
SWE
parsing
dependency-resolution
graph
Frequency
High
Last asked
2026-11-05
Stage
tech-screen · onsite-coding
Problem
- Accept a list of assignment expressions and return a mapping from every variable name to its computed value. Definitions can appear after their first use.
- Support expressions containing more than one operator and chains of dependencies. The initial examples use addition; a JavaScript configuration-parser version also discusses subtraction.
- Detect a dependency on a variable that is never defined. In the backend screen, print
Unresolvable equations. - Detect a cycle between variable definitions. In that screen, print
Cyclic Dependency. - A November 2026 phone screen asks for the values of all resolvable variables plus the list of unresolvable ones; its input defines
dtwice (see below). - In a 45-minute phone screen (October 2026), the problem was staged: Part 1 assumes the equations contain only addition and is run against test cases; Part 2 extends the code to subtraction and re-tests; Part 3 asks how other operators would be designed, answered verbally.
Examples
input: ["foo = bar + 5", "bar = 2", "abc = 3"]
output: {"foo": 7, "bar": 2, "abc": 3}
input: ["g = abc + foo", "foo = bar + 5", "bar = 2", "abc = 3"]
output: {"g": 10, "foo": 7, "bar": 2, "abc": 3}Phone-screen input with a self-reference and a redefinition:
a = b + c
d = d + 5
c = 5
d = 10The backend follow-up includes these failure cases:
foo: bar + 3
bar: abc + pqr + 2
=> Unresolvable equations
foo: bar + 3
bar: foo + 2
=> Cyclic DependencyPitfalls
- Whitespace handling matters: trailing spaces in names and expressions without spaces around operators can break token lookup.
- Evaluating only one pass can leave valid dependency chains unfinished. Undefined names and cycles must not cause an endless loop.
- Time is tight. A 45-minute screen typically spends about 5 minutes on introductions and 5 on Q&A, leaving roughly 35 minutes of coding. One backend interview left less than ten minutes for both error-handling extensions. In another screen, a new dependency-chain test arrived only after the initial tests passed.
- Interviewers respond well to clarifying requirements and walking through data structures, algorithm, and implementation steps before coding.
- Confirm the accepted operators and error-output contract first; they differ across versions.
- Agree whether a repeated definition (e.g.
d = d + 5thend = 10) means last-wins or unresolved.
Follow-ups
Report unresolvable and cyclic definitions with the agreed error strings.
Preparation
- In 25 minutes, implement tokenization and dependency evaluation for the stated operators, then run both examples and both error cases.
- In 10 minutes, add checks for whitespace, repeated variable references, a long dependency chain, and a self-cycle; explain how operator precedence would affect an extension.
Was this article helpful?
Comments
Sign in to join the discussion
Loading...
