I came across following problem:
'Find all the elements in an array which occur odd number of times'.
My thoughts about this are:
Use
HashMap
: Add values in the array as keys in the HashMap. The value corresponding to each key will be number of times that key is encountered.Sort the array using Quick sort in O(N log N) and then traverse through the array to check which elements occur odd number of times.
What do you think, is there any other approach to this? If no, then which of these 2 approaches is better?
Thanks in advance!