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
Coding & Algorithms
Software Engineer
Apple
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

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
BFS
graphs
shortest path
multi-target search
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported