Solved c++, easy based on simple theory


int mod = 1000003;

int fact(int n)
if(n==0) return 1 ; else return (n*fact(n-1)) %mod;

int Solution::findRank(string A) {

                string s=A ;
                int ans =0;
                int n=s.length();
                for(int i=0;i<n-1;i++)
                        int c=0;
                        for(int j=i+1;j<n;j++)
                            ans+=( (c*fact(n-i-1)) )%mod;
                            //cout << c <<" "<<ans<< endl;
                    return (ans+1 )%mod;
                    //cout << ans+1 ;



Hi! Can you explain the logic behind your approach?

#3 watch this video to get the logic


If their large number test case for submit is taking the factorial mod 100003, I don’t think it actually has the correct answer, but that is what you have to do get the same answer they do. I don’t think you can represent factorials larger than 20! in a 64 bit integer.