Count Pickup Clusters Where Pins Lie Within Walking Distance

Last updated: November 29, 2026

Quick Overview

Given pickup pins as (x, y) in meters and a walking radius r, two pins are linked if their Euclidean distance is at most r, and clusters are connected groups under this link. Return the number of clusters, faster than checking every pair.

Uber
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Given pickup pins as (x, y) in meters and a walking radius r, two pins are linked if their Euclidean distance is at most r, and clusters are connected groups under this link. Return the number of clusters, faster than checking every pair.

Uber suggests consolidated pickup spots at venues and airports, which starts from clustering requested pins. The onsite interviewer expects union find for the grouping and a spatial grid to avoid O(n^2) distance checks, and will probe the cell size choice.

What the Interviewer Expects
  • Model clusters as connected components of a distance graph
  • Use union find to merge linked pins
  • Bucket pins into grid cells of side r so only neighboring cells are checked
  • Compare squared distances to avoid square roots
  • Analyze average and worst case complexity
Key Topics to Cover
union find
spatial hashing
grid bucketing
clustering
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
  • How would you cluster on the sphere using lat and lng over large areas?
  • What if you want clusters capped at a maximum diameter instead of chaining?
  • How does this relate to DBSCAN?
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: list of (x, y) floats, radius r > 0.
  • Link if dx^2 + dy^2 <= r^2; clusters are transitive (single-linkage chaining).
  • Output: number of clusters....
High-Level Design

All-pairs checking is O(n^2). Put each pin in cell (floor(x / r), floor(y / r)). Any two pins within distance r must be in the same or adjacent cells (a 3 x 3 neighborhood), because a coordinate dif...


Submit Your Answer
Markdown supported

Related Questions