aboutsummaryrefslogtreecommitdiff
path: root/challenge-198/deadmarshal/d/ch1.d
blob: b9e20b6753021d21f225f884ebe636d2c073db95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import std.stdio:writeln;
import std.algorithm:sort;
import std.math:abs;

int max_gap(int[] arr)
{
  if(arr.length < 2) return 0;
  arr.sort;
  int i = 0,max = 0,count = 0,temp = 0;
  while(i < arr.length)
  {
    temp = abs(arr[i] - arr[i+1]);
    if(temp > max) max = temp;
    i += 2;
  }
  for(i = 0; i < arr.length-1; ++i)
    if(abs(arr[i] - arr[i+1]) == max) count++;
  return count;
}

void main()
{
  int[] a1 = [2,5,8,1];
  int[] a2 = [3];
  writeln(max_gap(a1));
  writeln(max_gap(a2));
}