Simple recursive solution using substr


#1

#define max 1000003

int fact(int n)
{
if(n==0)
{
return 1;
}

int ans=fact(n-1)%max;
return (ans*n)%max;

}

int Solution::findRank(string A) {
//Base Case
if(A.size()==0)
{
return 1;
}
int count=0;

for(int i=1;i<A.size();i++)
{
    if(A[i]<A[0])
    {
        count++;
    }
}

int ans=((count%max)*(fact(A.size()-1)%max)+findRank(A.substr(1))%max)%max;
return ans;

}