Let\'s say I have an array of ints {100, 80, 90, 100, 80, 60}
so I want to count those duplicates and save those counter for later. because each duplicate number sh
Use a std::map or std::unordered_map for counting the occurences.
Then iterate over the map and replace each value by the key divided by the original value (counter).
Finally go through the original array and replace each number by its mapped value.
If you use a std::unordered_map the algorithm is O(n). Your original one is O(n log n) because sorting is involved.