Find Services That Can Never Get Stuck in a Call Cycle

Last updated: November 29, 2026

Quick Overview

Services form a directed call graph where graph[i] lists the services that i calls. Return, in sorted order, every service from which every possible chain of calls eventually ends at a service that calls nothing.

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

0

0

0 solved


Services form a directed call graph where graph[i] lists the services that i calls. Return, in sorted order, every service from which every possible chain of calls eventually ends at a service that calls nothing.

Eventual safe states in the style of a Meta technical screen, framed around flagging microservices whose calls can never loop back into a deadlock. The interviewer checks that you can solve it with either three-color DFS or reverse-graph topological peeling, and explain why each is correct.

What the Interviewer Expects
  • Defines safe as: no path from the node reaches a cycle
  • Uses reverse edges and out-degree counts (Kahn style) or three-color DFS
  • Starts from terminal services with out-degree 0
  • Peels a node once all of its callees are known safe
  • Returns results sorted
Key Topics to Cover
Topological sort
Cycle detection
Reverse graph
Graphs
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
  • How would you report one cycle that makes a service unsafe?
  • What if the graph changes as services deploy?
  • How would you do this with recursive DFS, and what are the risks?
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: adjacency list graph of length n. Output: sorted list of safe services. A service is safe if every path from it reaches a terminal service. n up to 10^4, edges up to 4 * 10^4....

High-Level Design

A service is safe exactly when all its callees are safe; terminal services are safe by definition. Reverse every edge and record each node's out-degree. Queue all terminal nodes. When a node is confir...


Submit Your Answer
Markdown supported