Process Graph Rule Validation
Reported by candidates from Hadrian's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt on this Hadrian OA, reported August 2026, is enumerating paths. With 100000 nodes and 200000 edges, a DAG can have exponentially many complete paths, so brute force dies fast. This is a graph problem on a DAG, and the real move is a topological pass that tracks small state per node instead of whole paths. If you blank on the state design, StealthCoder is the invisible safety net that can hand you the structure while the assessment is live. Read the three rules carefully, because each one turns into a tiny flag you carry forward.
The problem
A process system is represented by a directed acyclic graph. Node i has type processTypes.charAt(i), one of A, B, C, or D. Each row [u, v] in edges means that process u can be followed directly by process v. A complete execution path starts at any node with indegree 0 and ends at any node with outdegree 0. The system is valid only if every complete execution path satisfies all three rules: The path contains at least one process of type B. No process of type A appears before a later process of type B on the same path. Every process of type D has at least one earlier process of type C on the same path. Return true when every complete execution path is valid; otherwise return false. Function isValidProcessSystem(processTypes: String, edges: int[][]) → boolean Examples Example 1 processTypes = "BCAD" edges = [[0,1],[1,2],[2,3]] return = true The only complete path is B -> C -> A -> D. It contains B, its B is before its A, and its D has an earlier C. Example 2 processTypes = "AB" edges = [[0,1]] return = false The path contains an A before a later B, which violates the second rule. Example 3 processTypes = "BCBD" edges = [[0,1],[0,2],[1,3],[2,3]] return = false The path 0 -> 2 -> 3 reaches D without an earlier C. One invalid complete path makes the whole system invalid. Constraints 1 <= processTypes.length <= 100000 Every character of processTypes is A, B, C, or D. 0 <= edges.length <= 200000 Every edge has the form [u, v], where 0 <= u, v < processTypes.length and u != v. The edges are unique and the directed graph is acyclic.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Process nodes in topological order (Kahn's algorithm) and carry a small state set per node. The rules are about order on a path, so track for each node the set of reachable states over all paths arriving there: seenB, seenC, and seenAWithoutLaterB. Rule 2 means an A followed later by B is bad, so when you hit B and an A was already seen on that path, fail. Rule 3: at a D, require seenC on every incoming path. Rule 1: at each sink, require seenB. Because you need every path to pass, propagate the worst case. For C and B, use AND over predecessors for 'guaranteed seen'. For A-before-B, use OR over predecessors. A common pitfall is mixing up AND and OR, or only checking one path. StealthCoder is your hedge if the propagation logic slips mid-assessment, but the flags are only three booleans.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Process Graph Rule Validation cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Hadrian's OA.
Hadrian reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Process Graph Rule Validation FAQ
What's the trick in Process Graph Rule Validation?+
Don't enumerate paths. Run a topological sort and propagate three booleans per node: guaranteed B seen, guaranteed C seen, and possible A seen. Check rules at B nodes, D nodes, and sinks. It's linear in nodes plus edges.
Why do I need AND for some flags and OR for others?+
You need every path valid. 'B seen' and 'C seen' must hold on all incoming paths, so combine with AND. 'An A appeared earlier' is a violation if any path has it, so combine with OR.
How hard is this Hadrian OA really?+
Medium. The graph traversal is standard, but the per-node state design is where people stall. Once you see that each rule collapses to a boolean, the code is short. The constraints rule out anything slower than O(V+E).
What edge cases should I test?+
A single node with no edges, which is both a source and a sink and needs to be B. Multiple sources and sinks. A diamond graph where one branch lacks C before D, like Example 3. Disconnected components also count.
How do I prepare in 48 hours?+
Write Kahn's algorithm from memory until it's automatic. Then practice DAG dynamic programming where you pass flags along edges. Run the three examples by hand, especially the diamond case, and confirm your AND/OR choices on them.