What's the problem in my code? Please help!

#include <algorithm>
#include <iostream>
#include <string>

int main() {
    int T = 0;
    std::cin >> T;
    while (T--) {
        int M = 0;
        std::cin >> M;
        std::string arr[M];
        for (int i = 0; i < M; ++i) { std::cin >> arr[i]; }
        std::sort(arr, arr + M);
        for (int i = M - 1; i >= 0; --i) { std::cout << arr[i]; }
        std::cout << '\n';
    }
}

hello @moon

consider this case->
1
2
2 21

here expected output is 221 but urs will give 212.

the logic is if a and b are two numbers then u can combine them in two ways either ab or ba right?
which ever combination give us maxium we will consider that order.
so just apply same logic in ur comparator

bool cmp(string a,string b){
return a+b > b+a;
} 

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.