aboutsummaryrefslogtreecommitdiff
path: root/challenge-194/deadmarshal/d/ch2.d
blob: 6e0cc3a6ff00fe1f4627e03f0de9c758887e70ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import std.stdio:writeln;
import std.algorithm:sort;

bool frequency_equalizer(string str)
{
  uint[char] hash;
  int[] vals;
  foreach(c;str) hash[c]++;
  foreach(k,v;hash) vals ~= v;
  vals.sort!("a > b");
  if((vals[0] == vals[1]+1) && (vals[$-1] == vals[1])) return true;
  return false;
}

void main()
{
  writeln(frequency_equalizer("abbc"));
  writeln(frequency_equalizer("xyzyyxz"));
  writeln(frequency_equalizer("xzxz")); 
}