I have an array of numbers. I need to find out what numbers are repeated and count the number of repetitions.
I'm thinking of doing this through 2 arrays:
In the first, I will write the number and in the second the number of repetitions of the element. But for this, each number will have to be constantly compared with the first array of numbers.
Do you have any ideas on how to make a faster algorithm?
Examples:
Array of numbers:
1 9 7 8 9 6 9 8 7 1
Two arrays that will come out as a result (if you know how to do it with one array, it will be cool):
1 array:
1 9 7 8 6
2 array:
2 3 2 2 1
std::unordered_map<int, int>?