Recursion lexilogical order hackerblocks

i try to solve this problem using convert array into string and using sort function to solve my problem but i get error so correct my code
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
int arr[n];
int i = 0;
while(n > 0){
arr[i] = n;
n–;
i++;

}


string str;

for(int i: arr){
str += to_string(i);
}

sort(str.begin(), str.end());

cout<<str<<" ";
return 0;
}

Hello @kshitiz.gzb,

Please, send you code using online Coding Blocks IDE next time.
The way you have shared it, is introducing many syntax errors.
Steps:

  1. Paste it on IDE
  2. Save it there
  3. Send the URL generated

Now, coming back to your question:
When i executed your code, It was not generating any error.
But, a wrong answer for sure.

To understand the reason,
Run the following code for 20:

Problem:
Wrong Output Format
Solution:
Rather use an array of strings str[n] of length n.

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

hey virender i use string but i now got erroe so give me some more detail or share a code of this problem

Hello @kshitiz.gzb,

I would give both.
But, first share your modified code. (Share using coding blocks IDE)

This way i can explain you the mistakes you were doing.:slightly_smiling_face:

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.