MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / eventualSafeNodes

Method eventualSafeNodes

FindEventualSafeStates.java:2–14  ·  view source on GitHub ↗
(int[][] graph)

Source from the content-addressed store, hash-verified

1class Solution {
2 public List<Integer> eventualSafeNodes(int[][] graph) {
3 // V+E
4 // V
5 HashMap<Integer,Boolean> map = new HashMap<>();
6 int n = graph.length;
7 List<Integer> res = new ArrayList<>();
8 for(int i=0;i<n;i++){
9 if(dfs(i,graph,map)){
10 res.add(i);
11 }
12 }
13 return res;
14 }
15 public boolean dfs(int node, int[][] graph, HashMap<Integer,Boolean> map){
16 if(map.containsKey(node)){
17 return map.get(node);

Callers

nothing calls this directly

Calls 2

dfsMethod · 0.95
addMethod · 0.45

Tested by

no test coverage detected