PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Liftoff

Find degrees of connection in a LinkedIn graph

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of graph traversal, reachability and shortest-path concepts along with the ability to manage performance constraints on large sparse graphs.

  • medium
  • Liftoff
  • Coding & Algorithms
  • Software Engineer

Find degrees of connection in a LinkedIn graph

Company: Liftoff

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given an undirected graph representing professional connections: - `n` people labeled `0..n-1` - a list of undirected edges `connections`, where `(a, b)` means `a` and `b` are directly connected (1st-degree) Given two people `src` and `dst`, return the minimum number of connections (degrees) needed to reach `dst` from `src`: - return `0` if `src == dst` - return `1` if directly connected - return `2` if connected via one intermediate person, etc. - return `-1` if `dst` is not reachable from `src` Optionally (if asked), also return one shortest path. Constraints: `1 ≤ n ≤ 1e5`, `0 ≤ |connections| ≤ 2e5`. The solution should be efficient.

Quick Answer: This question evaluates understanding of graph traversal, reachability and shortest-path concepts along with the ability to manage performance constraints on large sparse graphs.

Related Interview Questions

  • Compute the Eddington number from ride distances - Liftoff (medium)
  • Parse and expand an IPv6 address - Liftoff (medium)
  • Implement minimal RLE encode/decode with max run K - Liftoff (medium)
Liftoff logo
Liftoff
Feb 26, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
2
0

You are given an undirected graph representing professional connections:

  • n people labeled 0..n-1
  • a list of undirected edges connections , where (a, b) means a and b are directly connected (1st-degree)

Given two people src and dst, return the minimum number of connections (degrees) needed to reach dst from src:

  • return 0 if src == dst
  • return 1 if directly connected
  • return 2 if connected via one intermediate person, etc.
  • return -1 if dst is not reachable from src

Optionally (if asked), also return one shortest path.

Constraints: 1 ≤ n ≤ 1e5, 0 ≤ |connections| ≤ 2e5. The solution should be efficient.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Liftoff•More Software Engineer•Liftoff Software Engineer•Liftoff Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.