6 kyu
Getting MAD
687 of 1,219jteodoro
Description:
Getting the Minimum Absolute Difference
Task
Given an array of integers with at least 2 elements: a1, a2, a3, a4, ... aN
The absolute difference between two array elements ai
and aj
, where i != j
, is the absolute value of ai - aj
.
Return the minimum absolute difference (MAD) between any two elements in the array.
Example
For [-10, 0, -3, 1]
the MAD is 1
.
Explanation:
| -10 - 0 | = 10
| -10 - (-3) | = 7
| -10 - 1 | = 11
| 0 - (-10) | = 10
| 0 - (-3) | = 3
| 0 - 1 | = 1
| -3 - (-10) | = 7
| -3 - 0 | = 3
| -3 - 1 | = 4
| 1 - (-10) | = 11
| 1 - 0 | = 1
| 1 - (-3) | = 4
The minimum value is 1
( both | 0 - 1 |
and | 1 - 0 |
).
Note
Note that the same value can appear more than once in the array. In that case, the MAD will be 0
.
Fundamentals
Arrays
Algorithms
Similar Kata:
Stats:
Created | Jun 9, 2017 |
Published | Jun 9, 2017 |
Warriors Trained | 1897 |
Total Skips | 21 |
Total Code Submissions | 3528 |
Total Times Completed | 1219 |
Python Completions | 687 |
JavaScript Completions | 513 |
Haskell Completions | 23 |
λ Calculus Completions | 6 |
TypeScript Completions | 51 |
Prolog Completions | 5 |
Total Stars | 31 |
% of votes with a positive feedback rating | 91% of 231 |
Total "Very Satisfied" Votes | 194 |
Total "Somewhat Satisfied" Votes | 33 |
Total "Not Satisfied" Votes | 4 |
Total Rank Assessments | 13 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |