Let's say my array contains integers. I'd like to create lists, so that every list contains indexes where a particular value occured in the array. For instance, if the array was `5,0,3,5,2,5,3`, we would have 4 lists (as there were 4 values):

value 5: 0, 3, 5

value 0: 1

value 3: 2, 6

value 2: 5

Currently I am attempting to figure out the highest value (in this case *5*). Therefore, I create 5 lists and just add the index to the appropriate list (i.e. the 5th element of the array is 2, so I add index 5 to the 2nd list). The problem is that I created 5 lists, but there are actually 4 needed (we don't have 4 anywhere, so one list will be created unnecessarily).

Could anyone suggest a more efficient method?