Leetcode Problem 2581. Count Number of Possible Root Nodes
2581. Count Number of Possible Root Nodes
Leetcode Solutions
DFS & Memoization
Build an undirected graph using the edges array.
Build a directed graph using the guesses array.
Initialize a memoization dictionary to store the results of subproblems.
For each node i in the graph:
a. Perform DFS from node i, treating it as the root.
b. Count the number of correct guesses during the traversal.
c. If the count is greater than or equal to k, increment the result counter.
Return the result counter as the number of possible root nodes.