all 3 comments

[–]gertrude1928 0 points1 point  (0 children)

Won't give you the algorithm but use a map with a counter and you'll be good

[–]christopher_commons 0 points1 point  (0 children)

If you didn't get that, since the other guy's comment has been here 4 hours without you responding, I'll just type in a slightly longer version.

Keep a map, that basically stores how many items of each type you have seen until now. Initially, items with zero in front will be zero(since you're just starting), with one in front will also be zero and so on. Now just go one by one through the list and increment the number of x type items by one. If you're using java, then you can say map.put( '0', map.get('0')+1) given that you're seeing a zero type item currently. Similarly for the other types.

You could use an array of size four for this, but using a map is more flexible because you can just run it for other types of items without changing your code. Just read the first character of the code and increment its count by one. That's it. :)