Design error detection and propagation algorithms
SnowflakeSoftware Engineer · Technical ScreenLast updated
This question evaluates algorithm design and complexity-analysis skills across search and graph problems, specifically log search for first-error detection, reachability and failure propagation in directed service dependency graphs, and longest-path reasoning under cycle or DAG assumptions.
You are given three related sub-problems about error detection and propagation.
A) Log search: You have a chronologically ordered array of log lines. Each line starts with one of the exact prefixes "[Info]", "[Warn]", or "[Error]". Guarantees: after the first "[Error]" appears, every subsequent line is an "[Error]"; immediately before the first "[Error]" there is at least one "[Warn]". Find the index of the first "[Error]" using as few reads as possible. Implement the function and state time and space complexities. Clarify what you return if no error exists.
B) Failure fan-out: You are given a directed service dependency graph where an edge U -> V means "U calls V". When a service fails, all upstream callers that depend on it eventually fail. Given the ID of the first failing service and the graph (e.g., as an adjacency list of callers-to-callees), output the set of all services that will eventually fail (order not important). Describe and implement an algorithm and analyze its complexity.
C) Longest failure chain (follow-up): Using the same graph and initial failing service, output one of the longest error-propagation chains starting from that service (i.e., an ordered list of services describing a longest path of cascading failures along the propagation direction). State any assumptions about cycles (e.g., treat the graph as a DAG or search for the longest simple path), justify your choice, and provide the algorithm with complexity analysis.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.