Closest Random Points (Also for Core/Database Engineering)

Problem Overview

  • Find the squared shortest distance between any pair of 2D points.
  • Input: arrays x[n] and y[n] of integer coordinates; Output: a long with the minimum squared distance.
  • Constraints: n ≥ 2, with n ≤ 1000 or n = 100000; coordinates are uniformly random in [0, 10^9 − 1].
  • Real-world context: random spatial data and analytics; common geometry problem across systems.
  • Asked in Snowflake interviews; a coding interview 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: