Solution in CPP


#1

int mod=1000003;
int fact(int n)
{
if(n<=1) return 1;
return (nfact(n-1))%mod;
}
int Solution::findRank(string a) {
string s=a;int i,j;
int n=a.length();
sort(s.begin(),s.end());
int ans=1;int arr[n+1];
fill(arr,arr+n+1,0);
int len=n-1;
for(i=0;i<n;i++)
{
int cnt=0,ind;
for(j=0;j<n;j++)
{
if(s[j]==a[i])
{
ind=j;
break;
}
if(arr[j]==0) cnt++;
}
arr[ind]=1;
int tot=fact(len);
len–;
ans=(ans+(cnt
tot)%mod)%mod;
}
return ans%mod;
}