</>OfferRetriever
DashboardDiscuss
NEW

Spring Hire Sale

Limited Time Deal: Unlock all premium questions for over 30% off

$10.42$7.08

08

:

04

:

46

:

41

Get this deal
Back to Dashboard

Degrees of Separation

Medium

In a social network, there are n users numbered from 0 to n - 1. You are given a list of bidirectional friend connections connections, where each element [a, b] means user a and user b are friends. The degree of separation between two users is the minimum number of friend hops needed to get from one to the other.

Given n, connections, userA, and userB, return the minimum number of friend hops between userA and userB. Return 0 if userA == userB. Return -1 if no path exists. ...