DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
easy
Graph

Find Center of Star Graph

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **Find Center of Star Graph** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** Center appears in both first two edges **Edge Cases to Consider:** - (1) Star with 3 nodes - (2) All edges include center trivially - (3) Large star

Examples

Example 1
Input: [[1,2],[2,3],[4,2]]
Output: 2
Explanation: Center is 2
Example 2
Input: [[1,2],[5,1],[1,3]]
Output: 1
Explanation: Center is 1
Example 3
Input: [[1,2]]
Output: 1 or 2
Explanation: Two-node star (trivial)

Constraints

  • ▪2 <= vertices <= 1000
  • ▪0 <= edges <= 5000
  • ▪Avoid infinite cycles during depth traversal

Watch Out For Edge Cases

  • ▪Star with 3 nodes
  • ▪All edges include center trivially
  • ▪Large star
Frequently Asked At
AmazonMicrosoftGoogleTCS