All practice tasks

Coding (Algo)

Find the Closest Coordinate Pair

Sorting · Hard

A spatial inspection tool needs the minimum separation between recorded locations. Two different records can have exactly the same coordinates and must then produce zero separation. Large batches make comparing every pair too expensive; no map service or geometry library is available.

Return the minimum squared Euclidean distance between two different input indexes or null if fewer than two records exist.

Input

Call

  • Implement solve(input) and return the result. The provided adapter handles JSON input and output.

Input shape

{ points: [integer, integer][] }

Fields

  • points contains two-dimensional integer coordinates [x,y] in arbitrary order. Duplicate coordinates may occur at different indexes.

Output

Return value

  • Return an integer squared distance: (x1-x2)^2+(y1-y2)^2. Do not take a square root or round.
  • Two equal coordinate pairs at different indexes are a valid pair with result zero. Empty and singleton arrays return null.

Constraints

  • 0 <= points.length <= 100000; coordinates are integers from -1000000 to 1000000.
  • Squared distances and cross products fit safe JSON integers. Do not mutate points or its nested pairs.

Examples

Example 1

{
  "points": [
    [
      0,
      0
    ],
    [
      3,
      4
    ],
    [
      4,
      4
    ]
  ]
}

Returns

1

Example 2

{
  "points": [
    [
      2,
      3
    ],
    [
      2,
      3
    ]
  ]
}

Returns

0

Required complexity

O(n log(n + 1)) time and O(n) auxiliary space

What this task practices

Find the Closest Coordinate Pair is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as hard difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.