Form Biggest Number code not submitting

Here is my code it is , compiling in Coding Blocks IDE , and here while submitting it is showing output truncated.

//#include <bits/stdc++.h>
using namespace std;

void answer(vector arr, int m) {

sort(arr.begin(), arr.end());
string s = "";
for (int i = m; i >= 0; i--) {
	s = s + arr[i];
}
cout << s;

}

int convertToInt(string s){
int ans = 0;
int p = 1;

for(int i = s.length()-1; i>=0;i--){

	ans += ((s[i] - '0')*p);
	p = p*10;

}
return ans;

}

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//ios_base& scientific (ios_base& str);

int t;
cin >> t;

for (int i = 0; i < t; ++i) {
	int m;
	cin >> m;

	vector<string> arr;

	for (int i = 0; i < m; ++i) {
		string in;
		cin >> in;
		arr.push_back(in);
		/* code */
		
	}
	//string p = answer(arr, m);
	//cout<<convertToInt(p)<<endl;

	answer(arr,m);
}
return 0;

}

Please solve my query ASAP

Hello @Detoxo_16,

Mistakes:

  1. Wrong declaration of vector:
    void answer(vector arr, int m) {
    Correction:
    void answer(vector arr, int m) {

  2. This won’t pass all the test cases:
    Example:
    1
    3
    87 9 8
    Expected Output:
    9887
    Your Output:
    8798
    Reason:
    Sorting won’t help.
    Better Logic for comparator function:
    Concatenate two strings: ab=a+b and ba=b+a and compare them.

Code:

Hope, this would help.
Give a like if you are satisfied.

Here it is showing output truncated .
That is the error

Hello @Detoxo_16,

Correction:
for (int i = m-1; i >= 0; i–) {
s = s + arr[i];
}

Let me know if you still face the same error.

It worked.
Thanks for your help. :slight_smile:

Anytime @Detoxo_16,

Now, make the suggested modifications in your code to pass the test cases.

Also, mark it as resolved if you have no more doubts regarding this question.

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.