13Explain BFS and DFS and when to use each, then detect a cycle in a graph.▼mediumGoogleMetaAmazon1 replies○ sign inGraph traversal sits beneath a large family of interview problems. What matters is knowing the BFS-vs-DFS tradeoff (shortest path vs memory shape) and applying it cleanly, then getting the directed-vs-undirected cycle gotcha that trips up most candidates.Open full answer →
30Topological sort: order tasks with dependencies (and detect cycles).▼mediumGoogleMetaAmazon1 replies◆ premiumTopological sort arranges a DAG so dependencies come first, the backbone of build systems, schedulers, and ML/data pipeline DAGs. Interviewers look for Kahn's algorithm (or DFS) plus cycle detection. The answer follows.Open full answer →
31Union-Find (Disjoint Set Union): connectivity and grouping.▼mediumGoogleMetaAmazon1 replies◆ premiumUnion-Find answers 'are these in the same group?' almost instantly and drives connected-components, cycle detection, and clustering. Interviewers look for path compression plus union by rank for near-O(1) operations. The answer follows.Open full answer →
69Course Schedule: can you finish all courses given prerequisites (cycle detection)?▼medium★ EssentialGoogleMetaAmazon1 replies◆ premiumCourse Schedule collapses to a single question: is the prerequisite graph a DAG? The signal is seeing the graph framing and applying topological sort or DFS to detect a cycle. Here is the answer.Open full answer →
107Dijkstra's algorithm: shortest paths from a source in a weighted graph.▼mediumGoogleAmazonUber2 replies◆ premiumDijkstra computes single-source shortest paths in O((V+E) log V) with a min-heap, the backbone of routing and network latency problems. The signal is why it requires non-negative weights and how lazy deletion keeps the heap simple. Here is the answer.Open full answer →
108Bellman-Ford: shortest paths with negative edges and negative-cycle detection.▼mediumGoogleAmazonMicrosoft1 replies◆ premiumBellman-Ford copes with negative edge weights that break Dijkstra and detects negative cycles, the foundation of currency-arbitrage problems. The signal is the V-1 relaxation rounds plus the extra Vth round that flags a negative cycle. Here is the answer.Open full answer →
109Floyd-Warshall: all-pairs shortest paths with a three-loop dynamic program.▼mediumGoogleAmazonMicrosoft2 replies◆ premiumFloyd-Warshall computes shortest paths between every pair of nodes in O(V cubed) with a compact three-line triple loop. The signal is the intermediate-node DP order and why k has to be the outer loop. Here is the answer.Open full answer →
66What are Graph Neural Networks (GNNs), and how does message passing work?▼hardGoogleMetaPinterest2 replies◆ premiumGNNs power recommendations, fraud, and molecule modeling by learning over graph structure. What matters is the message-passing mechanism, why k-hop matters, and why you keep them shallow. Here is the answer.Open full answer →
14How do you query hierarchical data (org charts, category trees) in SQL with a recursive CTE?▼mediumSnowflakeDatabricksMicrosoft2 replies○ sign inHierarchies (org charts, bill-of-materials, category trees) call for recursion, and a self-join reaches only one level down. The signal is the recursive CTE with its anchor plus recursive members, and understanding how it terminates.Open full answer →
44Find shortest paths and detect cycles in a graph stored as edges, using a recursive CTE.▼hardSnowflakeDatabricksGoogle1 replies◆ premiumAn org-chart recursion walks a tree, but a general graph has multiple paths and back-edges. The signal is building up the visited path to prune cycles and ranking paths by cost to land the shortest one.Open full answer →
37Design a 'People You May Know' (friend/connection recommendation) system.▼hardMetaLinkedInGoogle1 replies◆ premiumPYMK is graph recommendation at billion-node scale. The interviewer is testing for one instinct: do you generate candidates from the social graph, or naively try to score every pair? Here is the design that holds up through the follow-ups.Open full answer →
83Design a misinformation / fake-news detection system at scale.▼hardMetaGoogleMicrosoft1 replies◆ premiumTruth is not a label you can gather cheaply, and adversaries adapt as soon as you ship. A strong answer combines content, graph, and behavioral signals, places humans in the loop where precision matters, and treats adversarial drift as a permanent operating condition rather than a one-time training problem.Open full answer →