← Uber Interview Insights

Uber·Software Engineer·Online Assessment (OA)·Intermediate

IntermediatePrefer not to say
May 2026Remote

Summary

Uber SWE online assessment, part of what looked like a Hack2Hire pipeline. One coding problem about connected components on a 2D grid. Pretty standard union-find territory but there's a sneaky edge case in the distance comparison that I almost got wrong.

Questions Asked (1)

Q1

Given a list of ball positions on a 2D grid and an integer d, find the minimum number of triggers needed to absorb all balls, where two balls connect if their Euclidean distance is strictly less than d, and connections are transitive.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is basically a connected components count dressed up in a physics metaphor.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a graph where each ball is a node and edges connect balls with Euclidean distance < d. The minimum number of triggers equals the number of connected components, which can be found using Union-Find (DSU) or BFS/DFS. For efficiency, avoid checking all pairs by using a spatial grid or sweep-line to find nearby balls.

Pro tip: Mention that the strict inequality (< d) means you must handle floating-point precision carefully, and that using squared distances avoids square roots. Also, discuss the trade-off between Union-Find with path compression (near O(n α(n))) and BFS/DFS (O(n + m)), noting that building the graph can be the bottleneck.

1. Clarify and Restate

Confirm the problem: given points and threshold d, find minimum triggers to absorb all balls, where connections are transitive. Clarify that a trigger absorbs a connected component, so the answer is the number of components.

2. Model as Graph

Represent each ball as a node. Add an edge between two balls if their Euclidean distance is strictly less than d. The problem reduces to counting connected components in this graph.

3. Choose Algorithm

Use Union-Find (DSU) to efficiently merge connected balls and count components, or BFS/DFS if the graph is sparse. Discuss time and space complexity trade-offs.

4. Optimize Edge Construction

Naively checking all pairs is O(n^2). Use a spatial grid with cell size d or a sweep-line to find neighbors within distance d, reducing time for large n.

5. Handle Edge Cases and Precision

Address empty list, single ball, and floating-point precision by comparing squared distances. Ensure strict inequality is correctly implemented.

Key Points to Mention

  • Graph connectivity and connected components
  • Union-Find (Disjoint Set Union) with path compression and union by rank
  • BFS/DFS for component counting
  • Spatial partitioning (grid) or sweep-line for efficient neighbor search
  • Time and space complexity analysis (e.g., O(n^2) vs O(n log n) with optimization)
  • Floating-point precision and using squared distances to avoid sqrt

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.