Simple solution using inbuilt function cpp


#1

long long int fact(int n){

return (n==0) || (n==1) ? 1 : (n* fact(n-1))%1000003;

}
int Solution::findRank(string A)
{
int mod=1000003;//318057
vector v;
int n=A.length();
for(int i=0;i<A.length();i++)
{
v.push_back(A[i]);
}
vector s(v.begin(),v.end());
sort(s.begin(),s.end());
long long int r=0;
for(int i=0;i<n;i++)
{
int a=v[i];
auto it=find(s.begin(),s.end(),a);
int in=it-s.begin();
r+=abs((long long int)(in)*fact(n-i-1))%mod;
if(i==n-1)
r++;
if(r>mod)
r=r%mod;
s.erase(it);
}
return r;
}