TikTok Server Network Optimization

Problem Overview

  • Compute the minimum total cost to connect all servers so each can communicate, where connecting i and j costs min(|x[i]-x[j]|, |y[i]-y[j]|).
  • Input: integer arrays x and y of length n; Output: an int for the minimum network cost.
  • Constraints: 2 ≤ n ≤ 1e5, 0 ≤ x[i], y[i] ≤ 1e9, duplicates allowed.
  • Real-world context: optimize TikTok’s grid-based server network expansion.
  • From TikTok 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: