PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Uber

Choose K pickup locations minimizing L1 distance

Last updated: Jun 14, 2026

Quick Overview

This question evaluates facility-location and spatial optimization skills under the Manhattan (L1) metric, testing algorithm design, combinatorial optimization, and handling geometric data.

  • medium
  • Uber
  • Coding & Algorithms
  • Machine Learning Engineer

Choose K pickup locations minimizing L1 distance

Company: Uber

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

## Coding: K Shuttle Pickup Locations (L1) You are given the coordinates of **N people** on a 2D grid. You want to open **K shuttle pickup locations** (pickup points) so that the **sum of Manhattan (L1) distances** from each person to their **nearest** pickup location is minimized. ### Input - An integer `N` (number of people). - An array `points` of length `N`, where `points[i] = (xi, yi)` are integer coordinates. - An integer `K` (number of pickup locations). ### Output - Return the **minimum possible total L1 distance**: \[ \sum_{i=1}^{N} \min_{j=1..K} (|x_i - X_j| + |y_i - Y_j|) \] where \((X_j, Y_j)\) are the chosen pickup locations. ### Clarifications / assumptions (state in your solution) - Are pickup locations required to be at integer coordinates? - Are pickup locations required to be chosen from existing people’s coordinates, or can they be anywhere? ### Constraints (you may assume) Provide an algorithm appropriate for interview constraints (e.g., `N` up to a few thousand, `K` up to `N`).

Quick Answer: This question evaluates facility-location and spatial optimization skills under the Manhattan (L1) metric, testing algorithm design, combinatorial optimization, and handling geometric data.

Related Interview Questions

  • Deep Equality of Two Records - Uber (medium)
  • Shortest Path in a Grid with Blocked Cells - Uber (medium)
  • Reconstruct the Alphabet Order of an Alien Language - Uber (medium)
  • Design and Implement an LRU Cache - Uber (medium)
  • Maximize Throughput and Count Trigger Components - Uber (medium)
Uber logo
Uber
Dec 15, 2025, 12:00 AM
Machine Learning Engineer
Onsite
Coding & Algorithms
30
0

Coding: K Shuttle Pickup Locations (L1)

You are given the coordinates of N people on a 2D grid. You want to open K shuttle pickup locations (pickup points) so that the sum of Manhattan (L1) distances from each person to their nearest pickup location is minimized.

Input

  • An integer N (number of people).
  • An array points of length N , where points[i] = (xi, yi) are integer coordinates.
  • An integer K (number of pickup locations).

Output

  • Return the minimum possible total L1 distance :

∑i=1Nmin⁡j=1..K(∣xi−Xj∣+∣yi−Yj∣)\sum_{i=1}^{N} \min_{j=1..K} (|x_i - X_j| + |y_i - Y_j|)∑i=1N​minj=1..K​(∣xi​−Xj​∣+∣yi​−Yj​∣)

where (Xj,Yj)(X_j, Y_j)(Xj​,Yj​) are the chosen pickup locations.

Clarifications / assumptions (state in your solution)

  • Are pickup locations required to be at integer coordinates?
  • Are pickup locations required to be chosen from existing people’s coordinates, or can they be anywhere?

Constraints (you may assume)

Provide an algorithm appropriate for interview constraints (e.g., N up to a few thousand, K up to N).

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Uber•More Machine Learning Engineer•Uber Machine Learning Engineer•Uber Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.