Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Find Champion II

Medium

Topics
Graph

There are n teams labeled 0..n-1 in a tournament. Each directed edge [u, v] means team u is stronger than team v. A team is the champion if no other team is stronger than it. Return the label of the unique champion, or -1 if it is not unique.

Example 1

Input:  n = 3, edges = [[0,1],[1,2]]
Output: 0

Example 2

Input:  n = 2, edges = [[0,1],[1,0]]
Output: -1

Constraints

  • 1 <= n <= 100
  • edges[i] = [u, v] with u != v.
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access