Building on the first version, the Find Champion II coding problem moves from a matrix to a directed acyclic graph (DAG). You are given teams and a list of directed edges [u, v], meaning team is stronger than team . A "champion" is a team that has no other team stronger than it. If there is exactly one such team, return its ID; otherwise, return -1.
Meta and Google ask this to evaluate your knowledge of Graph interview patterns, specifically In-degree calculation. It tests your ability to identify "source" nodes in a directed graph—nodes that have no incoming edges. It also evaluations your ability to handle ambiguity: if there are multiple teams with no superiors, there is no clear champion.
This problem is solved by calculating the In-degree of every node.
in_degree of size with zeros.[u, v], increment in_degree[v].in_degree == 0.Teams: 3, Edges: [[0, 1], [1, 2]].
in_degree: Team 0 = 0, Team 1 = 1 (from 0), Team 2 = 1 (from 1).Teams: 3, Edges: [[0, 2], [1, 2]].
in_degree: Team 0 = 0, Team 1 = 0, Team 2 = 2.Source nodes (in-degree 0) and sink nodes (out-degree 0) are the starting and ending points of many graph algorithms like Topological Sort. Mastery of degree counting is a prerequisite for more advanced graph problems.