Find Center of Star Graph (LeetCode 1791): Interview Notes
There is an undirected star graph with n nodes labeled 1..n. You are given a 2D integer array edges where each edges[i] = [ui, vi] indicates an edge. Return the center of the star graph.
Approach
The center appears in every edge. Compare the two endpoints of edges[0] against edges[1]: the shared node is the answer. No graph build needed.
Complexity
Time O(1), space O(1).
Practice tip
Keep the same narration under time pressure with AI interview assistant.
Disclosure: I work on Linkjob AI.