Validate Evaluation Chains and Resolve Boolean Outcomes
Company: Plaid
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: Resolve Boolean evaluation chains, detect cycles and paths into cycles, and handle disconnected components with a linear-time graph traversal.
Read the full Plaid Software Engineer interview experience this question came from
Constraints
- 0 <= n <= 200000, where n is the length of targets.
- Each target is -2, -1, or an integer from 0 through n - 1; there are no missing evaluation references.
- Every evaluation has exactly one target. Several evaluations may share a target.
- Self-loops are cycles, and disconnected components must all be checked.
- For an empty collection, return []; the collection has no invalid evaluations.
- Each returned value is -1, 0, or 1; every input and output value fits in a signed 32-bit integer.
- Aim for O(n) total time and O(n) additional space.
Examples
Input: ([],)
Expected Output: []
Explanation: Empty collection: there are no evaluations, so the result is empty and the collection has no invalid evaluations.
Input: ([-2],)
Expected Output: [1]
Explanation: Smallest non-empty input: the single evaluation points directly at true, so it resolves to 1.
Hints
- Every evaluation has exactly one target, so an evaluation's outcome is fully determined by the outcome of the single evaluation or terminal it points at.
- Reaching a node that is still part of the path you are currently following means something different from reaching a node whose final outcome has already been established.
- The stated O(n) bound means each evaluation should be touched a constant number of times overall, and chains can be up to 200000 long, so avoid deep recursion.