Minimum Relay Hops for a Find My Offline Beacon
Last updated: November 29, 2026
Quick Overview
Devices form an undirected proximity graph. Given the id of a lost offline AirTag and a set of devices that currently have internet access, return the minimum number of Bluetooth relay hops needed for the AirTag's beacon to reach any online device, or -1 if it cannot.
Apple
November 29, 20260
0
0 solved
Devices form an undirected proximity graph. Given the id of a lost offline AirTag and a set of devices that currently have internet access, return the minimum number of Bluetooth relay hops needed for the AirTag's beacon to reach any online device, or -1 if it cannot.
Find My's crowd-sourced network is a distinctive Apple product, and this question tests breadth-first search on an unweighted graph with multiple targets. The interviewer checks that you stop at the first online device found and handle disconnected graphs.
What the Interviewer Expects
- Model devices and proximity links as an adjacency list
- Use BFS because every hop has equal cost
- Stop as soon as an online device is dequeued
- Track visited nodes to avoid cycles
- Handle the case where the source itself is online
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Return the actual relay path for diagnostics.
- Each relay drains battery; prefer paths through devices with more charge.
- The graph changes as people move; how would you recompute efficiently?
- Find, for every device, its distance to the nearest online device.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: n devices labeled 0..n-1, an edge list of proximity pairs, source, and a set online. Output: minimum hop count to any online device, 0 if the source is online, -1 if unreachable....
High-Level Design
Build an adjacency list. Run BFS from the source, storing distance with each queued node. The first time we pop a node in online, its distance is minimal because BFS explores in nondecreasing distan...