Find minimum activations to absorb all balls
Company: Uber
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Take-home Project
Quick Answer: This question evaluates the ability to model Euclidean-distance relations as a static connectivity graph and reason about the minimum number of activations needed to absorb all nodes, testing computational geometry and graph algorithms competency.
Constraints
- 0 <= n <= 2000
- len(x) = len(y) = n
- -10^9 <= x[i], y[i] <= 10^9
- 0 <= d <= 10^9
- Two balls are connected only if their Euclidean distance is strictly less than d
Examples
Input: (6, [0, 1, 10, 11, 50, 51], [0, 0, 0, 0, 0, 0], 2.0)
Expected Output: 3
Explanation: Balls (0,1), (10,11), and (50,51) each form separate attraction groups, so one activation is needed for each group.
Input: (3, [0, 1, 2], [0, 0, 0], 1.5)
Expected Output: 1
Explanation: Ball 0 attracts 1, and 1 attracts 2. Even though 0 and 2 are not directly connected, all three are in one chain, so one activation is enough.
Input: (2, [0, 3], [0, 4], 5.0)
Expected Output: 2
Explanation: The distance is exactly 5, but attraction requires the distance to be strictly less than d, so these balls are not connected.
Input: (3, [1, 1, 2], [1, 1, 2], 0.0)
Expected Output: 3
Explanation: With d = 0, even balls at the same coordinates do not attract because 0 is not strictly less than 0. Each ball must be activated separately.
Input: (0, [], [], 10.0)
Expected Output: 0
Explanation: There are no balls to absorb, so zero activations are required.
Hints
- Model each ball as a node in an undirected graph, and connect two nodes if their distance is less than d.
- Each activation absorbs exactly one connected component, so the answer is the number of connected components.