Halloween SalePremium questions, over 30% offUnlock all premium questions for over 30% off
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.
...
Asked at:Pinterest
More Pinterest interview questions
- Directory Permission Managermedium
- EV Charging Optimizermedium
- Audit Log Analyzermedium
- Remove a Forest Subtreemedium
- Scooter Street Ride Simulationeasy
- Distribute Ads Across Columnseasy
- Find Unallocated Bucket ID Rangesmedium
- Single Bubble Explosionmedium
OfferRetriever
Master technical interviews with real questions from top companies. Build your confidence and career.
LEGAL
© 2026 Purple Business Holdings LLC. All rights reserved. See Terms of Service.