A numerical sequence can be represented by an array in two ways
// an arbitrary sequence can be represented like this
const A = [1, 1, 2, 2, 2, 4, 4, 8, 8];
The same sequence cn be represented by counting the number of occurrences of each element. The above sequence can be represented like this
// A[n] = number of n's in the sequence
const A = [0, 2, 3, 0, 2, 0, 0, 2];
- 0 occurs 0 times
- 1 occurs 2 times
- 2 occurs 3 times
- and so on until number 8
If the sequence contains negative numbers, all the elements should be shifted by a number large enough to make them all greater than or equal to zero. Or the negative numbers can be added to another array