1065. Maximal Network Rank

MediumGraphsDFSGraph

Given n cities and undirected roads (edges), the network rank of two different cities is the total number of roads connected to either city, counting a road between them only once. Return the maximum network rank over all pairs of cities. The input is JSON {n, edges}.

Input: JSON {n, edges}.

Output: Integer — the maximal network rank.

Examples

Example 1
Input: {"n":4,"edges":[[0,1],[0,3],[1,2],[1,3]]}
Output: 4
Explanation: Cities 0 and 1 give rank 4.
Example 2
Input: {"n":2,"edges":[[0,1]]}
Output: 1
Explanation: Shared road counted once.
Example 3
Input: {"n":3,"edges":[]}
Output: 0
Explanation: No roads.

Constraints

Asked by

Microsoft
Solve this problem in the editor →