without using any additional buffer NOTE: One or two additional variables are fine
An extra copy of the array is not
FOLLOW UP
Write the test cases for this method*/
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int partition(string str, int b, int e){
int j = b + 1;
for (int i = b + 1; i <= e; i++){
if(str[i] < str[b]){
swap(str[i],str[j]);
j++;
}else if (str[i] == str[b]) return -1;
}
swap(str[j],str[b]);
return j;
}
bool judge_qs(string str,int b, int e){
if(b < e){
int p = partition(str,b,e);
if (p == -1 || judge_qs(str,b,p-1) == false || judge_qs(str,p+1,e) == false)
return false;
}
return true;
}
int main()
{
string str;
cin>>str;
cout<<judge_qs(str,0,str.length()-1)<<endl;
}