Iterative O(n^2) C++ approach


#1

long long int fact(long long int a){
if( a==0 || a==1 ){
return 1;
}
return (a%1000003)*(fact(a-1)%1000003);
}

int Solution::findRank(string s){

vector ch;
long long int rank = 0;
int count=0;
for(int i=0; i<s.length(); ++i){

count=0;
for (int j = i+1 ; j < s.length()  ; ++j)
{
	/* code */
	if(s[j]<s[i]){
		count++;
	}
}
rank+=(((count*fact(s.length() - (i) - 1 ))%1000003)%1000003);

}
return (rank+1)%1000003;
}