Description

Given an undirected star graph (a center node connected to all others), find and return the center of the graph.

Examples

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

Node 2 is center.

Input:edges = [[5,7],[6,7],[7,8]]
Output:7
Explanation:

In a star graph, the center node appears in every edge. Node 7 appears in all three edges [5,7], [6,7], and [7,8], while nodes 5, 6, and 8 each appear in only one edge.

Input:edges = [[3,9],[9,1],[9,4],[2,9],[9,10]]
Output:9
Explanation:

Node 9 is connected to all other nodes (3, 1, 4, 2, 10) making it the center of this 6-node star graph. The center node appears in all 5 edges while each leaf node appears in exactly one edge.

Constraints

  • 3 ≤ n ≤ 10⁵

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!