ok, I don't know what exactly you want the output to look like, but I can see that
in you'r code there's a needless repetition, for example, you count that number '1' is repeated 3 times
3 different times!, so what I suggest to you to indicate the a certain number is checked, for Example, when you checked
for number 1 remove it from the array!, what do I mean by remove, if you have for example a postiive array you can put '-1'
to mark that an element is removed from here and skip, so you don't count the repition of number '1' many times.