Minimum Gap

MediumAcc. 89.4%
+35 XP 15

Closest Pair

What is the smallest gap between any two numbers in the list?

The Assignment

Your function receives nums.

  1. Use nested loops to compare every pair.
  2. Track the minDiff.
  3. Print the result.

01EXAMPLE 1

Input[10, 2, 8]
Output2

Explanation: 8 and 10 have difference 2.

Constraints

  • Simple O(n²) comparison.
ArraysOptimization
JavaScript
Loading...
1 Hidden

Input Arguments

nums[10,2,8]

Expected Output

2

Click RUN to test your solution