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

Stats:

CreatedJun 9, 2017
PublishedJun 9, 2017
Warriors Trained1897
Total Skips21
Total Code Submissions3528
Total Times Completed1219
Python Completions687
JavaScript Completions513
Haskell Completions23
λ Calculus Completions6
TypeScript Completions51
Prolog Completions5
Total Stars31
% of votes with a positive feedback rating91% of 231
Total "Very Satisfied" Votes194
Total "Somewhat Satisfied" Votes33
Total "Not Satisfied" Votes4
Total Rank Assessments13
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • jteodoro Avatar
  • raulbc777 Avatar
  • JohanWiltink Avatar
  • monadius Avatar
  • stellartux Avatar
  • trashy_incel Avatar
  • ejini战神 Avatar
  • Kacarott Avatar
  • MikeBeloborodov Avatar
  • saudiGuy Avatar
Ad