Solved it using Recurssion


#1

long long int fac(int n) {
int a=1;
for(int i=1;i<=n;i++) {
a=(a*i)%1000003;
}
return a;
}
int Srank(string A) {
if(A.length()==1) {
return 1;
}
else {
string B=A;
sort(B.begin(),B.end());

size_t n=B.find(A[0]);
int m=A.length();
A.erase(A.begin());
return ((((int)n*fac(m-1)%1000003)%1000003)+Srank(A))%1000003;
}

}
int Solution::findRank(string A) {
return Srank(A)%1000003;
}