Answer: L3HARRIS TECHNOLOGIES | Online Interview Question | Off-Campus OA(2023)
Answer · Posted Jun 2026
Approach Build an adjacency list from the given edges. Store all restricted nodes in a HashSet. Perform DFS (or BFS) starting from node 0. Skip restricted and already visited nodes. Count every reachable node. Strategy Convert the edge list into an adjacency list. Use a HashSet for constant-time lookup of restricted nodes. Traverse the graph using DFS. Count every valid visited node. Java Code import java.util.*; class Solution { public int reachableNodes(int n, int[][] edges, int[] restricted) { List<List<Integer>> graph ...
The full answer & interview discussion are available to premium members.
Log in Create a free account