Solution for this problem is related to finding a rank of word in dictionary go learn how to find rank of word in dictionary from youtube


#1

int fact(int f){
if(f==0)
return 1;

return f*fact(f-1)%1000003;

}

int Solution::findRank(string A) {
int n = A.size()-1;
long long int rank=0;
for(int i=0 ;i<A.size()-1;i++){
int count=0;
for(int j = i+1;j<A.size();j++){
if(A[i]>A[j])
count++;
}
if(count>0)
rank=rank+(fact(n)*count)%1000003;
n–;
}

return (rank+1)%1000003;

}