Evaluate Tax Form Lines That Reference Other Lines

Last updated: November 29, 2026

Quick Overview

A tax form is a set of lines where each line is either a constant or a weighted sum of other lines (for example line 15 = line 9 minus line 12). Compute every line's value in a valid order and report a clear error if the lines reference each other in a cycle.

Intuit
Coding & Algorithms
Software Engineer
Intuit
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


A tax form is a set of lines where each line is either a constant or a weighted sum of other lines (for example line 15 = line 9 minus line 12). Compute every line's value in a valid order and report a clear error if the lines reference each other in a cycle.

TurboTax and Lacerte model forms as thousands of interdependent calculations, and engineers on the tax engine teams must reason about dependency order and circular references. The interviewer checks that you recognize a DAG evaluation problem, use topological sort, and produce a useful diagnostic when the graph is not a DAG.

What the Interviewer Expects
  • Model lines as nodes and references as directed edges from dependency to dependent
  • Use Kahn's algorithm (or DFS with colors) to get an evaluation order
  • Detect cycles and name the lines involved
  • Validate references to lines that do not exist
  • Explain how to recompute only affected lines after one input changes
Key Topics to Cover
topological sort
Kahn's algorithm
cycle detection
dependency graphs
incremental recomputation
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • A user edits line 1a. How do you recompute only the lines downstream of it?
  • How would you report the exact cycle path rather than every line stuck in it?
  • Some lines use max or min, such as a deduction capped at a limit. How does the design change?
  • How would you evaluate tens of thousands of lines across many forms efficiently?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input is a dict line_id -> number or line_id -> [(coef, dep_id), ...]. Output is a dict of computed values. Errors: a reference to an unknown line, or a circular reference. Values are plain number...

High-Level Design

Each formula line depends on its referenced lines, so build edges dep -> line and count in-degrees. Constants have in-degree 0 and start the queue. Repeatedly pop a ready line, compute it (all its d...


Submit Your Answer
Markdown supported