My test cases are running fine but don’t know why this code is giving runtime error while submission.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
//Start from here
int t;
cin>>t;
while(t--){
string s;
cin>>s;
//find the min character in the string
char small='|';//taking the max char
int pos=-1;
//to capture the location of the min char aswell
for(int i=0;i<s.size();i++){
if(s[i]<=small){
small=s[i];
pos=i;
}
}
if(pos<=0){
cout<<s;
}else{
//now take a vector and store big elements in it
vector<char> bade;
vector<char> chote;
for(int i=0;i<=pos;i++){
if(s[i]>small)bade.push_back(s[i]);
else chote.push_back(s[i]);
}
//now talking about the left elements .... after pos + 1
if(pos==s.size()-1){
//means no element after it....
//do nothing
}
else{
if(s[pos+1]<bade[bade.size()-1]){
//append the left elements at the end of chote
for(int i=pos+1;i<s.size();i++){
chote.push_back(s[i]);
}
}
else {
//append at the end of bade
for(int i=pos+1;i<s.size();i++){
bade.push_back(s[i]);
}
}
}
//print the chote and bade
for(auto &x : chote)cout<<x;
for(auto &x : bade)cout<<x;
}
cout<<endl;
}
}