PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Uber

Minimum Delivery Cost Between Cities

Last updated: Jul 17, 2026

Quick Overview

This coding interview question evaluates cost optimization and routing over a city network with value-based moves and conditional directed discounts. It tests practical algorithm design, edge-case interpretation, and complexity analysis for repeated minimum-cost queries.

  • medium
  • Uber
  • Coding & Algorithms
  • Software Engineer

Minimum Delivery Cost Between Cities

Company: Uber

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

# Minimum Delivery Cost Between Cities Implement `minimum_delivery_costs(delivery_charges, queries)`. There are `n` cities indexed from `0` to `n - 1`, and city `i` has value `delivery_charges[i]`. A delivery can move from any city `i` to any different city `j`: - The normal move cost is `abs(delivery_charges[i] - delivery_charges[j])`. - If `j` is the unique city whose value is closest to city `i`'s value, the move from `i` to `j` instead costs `1`. - If two or more cities tie for closest to `i`, city `i` has no discounted move. A route may use intermediate cities. For each `(start, end)` query, return the minimum total cost to reach `end` from `start`. ## Constraints - `2 <= n <= 2,000` - All delivery charges are distinct signed 32-bit integers. - `1 <= len(queries) <= 2,000` - Query endpoints are valid city indices. - Costs fit in signed 64-bit integers. ## Candidate clarifications Confirm whether closest-city ties disable the discount, whether the cheap edge is directed, and whether routes may visit intermediate cities.

Quick Answer: This coding interview question evaluates cost optimization and routing over a city network with value-based moves and conditional directed discounts. It tests practical algorithm design, edge-case interpretation, and complexity analysis for repeated minimum-cost queries.

Related Interview Questions

  • Kth Employee Reached in an Ordered Hierarchy - Uber (medium)
  • Last Truck to Leave a One-Dimensional Lane - Uber (medium)
  • Thread-Safe Token-Bucket Rate Limiter - Uber (medium)
  • Quadtree for 2D Geospatial Points - Uber (medium)
|Home/Coding & Algorithms/Uber

Minimum Delivery Cost Between Cities

Uber logo
Uber
Jul 3, 2026, 12:00 AM
mediumSoftware EngineerTake-home ProjectCoding & Algorithms
3
0

Minimum Delivery Cost Between Cities

Implement minimum_delivery_costs(delivery_charges, queries).

There are n cities indexed from 0 to n - 1, and city i has value delivery_charges[i]. A delivery can move from any city i to any different city j:

  • The normal move cost is abs(delivery_charges[i] - delivery_charges[j]) .
  • If j is the unique city whose value is closest to city i 's value, the move from i to j instead costs 1 .
  • If two or more cities tie for closest to i , city i has no discounted move.

A route may use intermediate cities. For each (start, end) query, return the minimum total cost to reach end from start.

Constraints

  • 2 <= n <= 2,000
  • All delivery charges are distinct signed 32-bit integers.
  • 1 <= len(queries) <= 2,000
  • Query endpoints are valid city indices.
  • Costs fit in signed 64-bit integers.

Candidate clarifications

Confirm whether closest-city ties disable the discount, whether the cheap edge is directed, and whether routes may visit intermediate cities.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Uber•More Software Engineer•Uber Software Engineer•Uber Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

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

Product

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

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding 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.