Compute the frequency of each element in an array -- Amazon