Find Minimum Dist.

Problem Overview

  • Given two arrays of 1D coordinates for data centers and servers, pair each center with exactly one server to minimize the absolute distance (lag).
  • Input: n (1≤n≤1e5), arrays center and destination with values up to 1e9; Output: the minimum total lag or an optimal pairing achieving it.
  • Real-world context: assigning servers to data centers to reduce network latency in infrastructure planning.
  • From Amazon interviews; a coding interview problem and common interview question.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: