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

Find Center of Star Graph

Easy

Topics
Graph

You are given an undirected star graph of n nodes labeled 1..n. A star graph has one center node connected to every other node, and no other edges. Given its edges, return the label of the center node.

Example 1

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

Example 2

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

Constraints

  • 3 <= n <= 10^5
  • The given graph is a valid star graph.
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