Shortest Distance in Line

ASKED IN INTERVIEW
2pts
Geometry

Problem Statement

You are given a table containing points on a 1D coordinate axis (the x-axis). Your goal is to find the shortest distance between any two distinct points.

The distance between two points x1 and x2 is defined as the absolute value of their difference: |x1 - x2|.

Rules:

  • You must find the single smallest distance found between any two unique points.
  • Output column: shortest.
  • The result should be a single value.
Tests your understanding of
Self-Join, Absolute Value and Aggregation

Input Tables

point
x(INTEGER)
-1
0
2
point_metadata
x(INTEGER)label(VARCHAR)
-1A
0B
2C
axis_info
axis_id(INTEGER)axis_name(VARCHAR)
1Horizontal

Expected Output

shortest(INTEGER)
1

Tags

EasyASKED IN INTERVIEWSelf-JoinAbsolute ValueAggregation
10-15 min
78%

Hints