First Eligible Partner in a Social Graph
Updated
Problem statement
Given an undirected social graph of n people, return the eligible person you can reach from start in the fewest hops. A hop is one move along a link. People are numbered 0 through n - 1, and each row [u, v] in edges is one social link. In the array eligible, eligible[i] == 1 means person i counts as an eligible partner.
start is never their own partner. If several eligible people are equally close, return the smaller person ID. Return -1 if no eligible partner can be reached.
Function
findFirstEligiblePartner(n: int, edges: int[][], start: int, eligible: int[]) → intExamples
Example 1
n = 6edges = [[0,1],[0,2],[1,3],[2,4],[3,5]]start = 0eligible = [0,0,0,1,1,1]return = 3People 3 and 4 are both two hops away. The smaller ID, 3, wins the tie.
Example 2
n = 4edges = [[0,1]]start = 0eligible = [1,0,1,0]return = -1The starting person is excluded, and the only other eligible person is disconnected.
Example 3
n = 5edges = [[0,4],[0,2],[4,3]]start = 0eligible = [0,0,1,0,1]return = 2People 2 and 4 are each one hop away, so the smaller ID is returned.
Constraints
1 <= n <= 100000.0 <= edges.length <= 200000.- Every edge joins two different valid person IDs.
- Edges are unique and undirected.
eligible.length == nand every value is0or1.0 <= start < n.
More Bloomberg LP Phone Screen questions
- Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Detonate the Maximum BombsZomato / Eternal · PHONE SCREENZomato / Eternal interview questions
- Minimize CommuteDatabricks · OA · PHONE SCREENDatabricks interview questions
- Shortest Word Chain Between Two WordsFanatics · PHONE SCREEN
- Course ScheduleByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
- Merge Accounts by Shared AttributeAmazon · PHONE SCREEN
- Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
- Shortest Pin Path Through TopicsPinterest · PHONE SCREENPinterest interview questions
- Shortest Travel Time in a Grid with Traffic LightsWaymo · PHONE SCREENWaymo interview questions
- Word Chain Jumps in a GridGoogle · PHONE SCREENGoogle interview questions
- Evaluate DivisionApple · PHONE SCREENApple interview questions