FunctionRacerProblemsRace

Busiest Node

EasyGraphsPython, JavaScript, TypeScript, Java, C++

An undirected graph has n nodes numbered 0 to n - 1. edges is a list of pairs [a, b], each an edge between a and b. The degree of a node is the number of edges that touch it; if the same pair appears several times, each copy counts.

Return the node with the largest degree. If several nodes share the largest degree, return the smallest of them. When edges is empty every degree is 0, so return 0.

Example 1

n 4
edges [[0,1],[1,2],[1,3]]
returns 1

Node 1 touches all three edges, so its degree 3 is the largest.

Example 2

n 3
edges [[0,1],[1,2],[0,2]]
returns 0

Every node has degree 2; the smallest of them is 0.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Graphs problems