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.
- Use nested loops to compare every pair.
- Track the
minDiff. - Print the result.
01EXAMPLE 1
Input
[10, 2, 8]Output
2Explanation: 8 and 10 have difference 2.
Constraints
- Simple O(n²) comparison.
ArraysOptimization
JavaScriptSystem handles I/O — write your function only
Loading...
1 Hidden
Input Arguments
nums[10,2,8]
Expected Output
2
Click RUN to test your solution