All practice tasks

Coding (Algo)

Find the Closest Pair of Measurements

Sorting · Easy

A diagnostics report contains unsorted integer measurements. It needs the smallest difference between any two observations. The same numeric measurement at two different positions is a valid pair with zero difference.

Return the minimum absolute difference between values at two distinct input positions.

Input

Call

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

Input shape

{ nums: integer[] }

Fields

  • nums is an array of signed integers. Repeated values at different positions are separate entries.

Output

Return value

  • Return the gap, not the pair or its positions. Return null with fewer than two observations.
  • Equal measurements at different positions produce zero. Input order must remain unchanged.

Constraints

  • 0 <= nums.length <= 100000; -1000000000 <= nums[i] <= 1000000000.
  • All totals and counts fit exactly in a safe JSON integer.

Examples

Example 1

{
  "nums": [
    9,
    1,
    5,
    8
  ]
}

Returns

1

Example 2

{
  "nums": [
    4,
    4
  ]
}

Returns

0

Required complexity

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

What this task practices

Find the Closest Pair of Measurements 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 easy 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.