# Learn Algorithms from LeetCode-121 (0802. Find Eventual Safe States)

## Categories: Graph/DFS, Level: Medium

Introduction: (Basic + Advanced + Interview Edition)

Learning Algorithms from LeetCode + Interview Success Guide

(Regular price: 3591 NTD, Discounted price until 2024/05/16 23:59)

https://hiskio.com/bundles/egb397?s=tc

(Regular price: 3990 NTD, Valid for a long term)

https://bit.ly/lc2022all

Please help me click on the “SHOW EMBED” below and give it 5 likes~ If you like it, you can also give me a round of applause~

(Liking doesn’t cost anything, thank you for supporting my writing~)

**Question:**There is a directed graph of

`n`

nodes with each node labeled from `0`

to `n - 1`

. The graph is represented by a **0-indexed**2D integer array

`graph`

where `graph[i]`

is an integer array of nodes adjacent to node `i`

, meaning there is an edge from node `i`

to each node in `graph[i]`

.A node is a **terminal node** if there are no outgoing edges. A node is a **safe node** if every possible path starting from that node leads to a **terminal node** (or another…