Suppose I have a vector as follows:
std::vector<int> v = {3, 9, 7, 7, 2};
I would like to sort this element vector so that the vector is saved as 77932. So, first we save the common elements (7), then we sort the remaining elements from the highest to the lowest.
If I have a vector as follows
std::vector<int> v = {3, 7, 7, 7, 2};
Here it will lead to 77732.
Same for
std::vector<int> v = {7, 9, 2, 7, 9};
this should result in 99772 because 9s are above 7s.
Last example
std::vector<int> v = {7, 9, 7, 7, 9};
this should lead to 77799, because there are more 7s than 9s.
What could be the fastest algorithm to implement this?