Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Maximal Network Rank

Medium

Topics
GraphArray

There are n cities and some undirected roads given as edges. The network rank of two different cities is the total number of roads directly connected to either city; a road connecting both counts only once. Return the maximum network rank over all pairs of cities.

Example 1

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

Example 2

Input:  n = 5, edges = [[0,1],[0,3],[1,2],[1,3],[2,3],[2,4]]
Output: 5

Constraints

  • 2 <= n <= 100
  • No repeated roads and no self-loops.
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access