Skip to content

2924. Find Champion II #879

Answered by mah-shamim
mah-shamim asked this question in Q&A
Nov 26, 2024 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

We need to identify the team(s) with an in-degree of 0 in the given Directed Acyclic Graph (DAG). Teams with no incoming edges represent teams that no other team is stronger than, making them candidates for being the champion. If there is exactly one team with an in-degree of 0, it is the unique champion. If there are multiple or no such teams, the result is -1.

Let's implement this solution in PHP: 2924. Find Champion II

<?php
/**
 * @param Integer $n
 * @param Integer[][] $edges
 * @return Integer
 */
function findChampion($n, $edges) {
    // Initialize in-degrees for all teams
    $inDegree = array_fill(0, $n, 0);

    // Calculate the in-degree for each team
    foreach ($edges as $edge

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Nov 26, 2024
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants