aboutsummaryrefslogtreecommitdiff
path: root/challenge-276/deadmarshal/d/ch2.d
blob: dcbf95de1fa1abcc585dd4fb895fdf0ee22f1a03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import std.stdio:writeln;
import std.algorithm:maxElement,filter,sum;
import std.array:array;

int maximum_frequency(int[] arr)
{
  int sum = 0;
  int[int] h;
  foreach(e;arr) h[e]++;
  int max = h.values.maxElement;
  return h.values.filter!(a => a == max).array.sum;
}

void main()
{
  writeln(maximum_frequency([1,2,2,4,1,5]));
  writeln(maximum_frequency([1,2,3,4,5]));
}