Skip to content

Instantly share code, notes, and snippets.

@nimbus98
Last active October 14, 2018 22:44
Show Gist options
  • Save nimbus98/e340e9407052efa4708b3e0c47d21755 to your computer and use it in GitHub Desktop.
Save nimbus98/e340e9407052efa4708b3e0c47d21755 to your computer and use it in GitHub Desktop.
IEEE CodeBuddy | Week 2 | Aravind Sai K & Akash Nair
int fact(int n)
{
int i = 0,ans = 1;
for(i=1;i<=n;i++)
{
ans = ans*i;
ans = ans%1000003;
}
return ans;
}
int Solution::findRank(string A) {
int i=0,j,k,ans=0;
vector<int> arr;
while(A[i] != '\0')
{
j = i;
k = 0;
while(A[j] != '\0')
{
if(A[i] > A[j])
k++;
j++;
}
arr.push_back(k);
i++;
}
k = 0;
i = arr.size()-1;
j = 0;
while(i >= 0)
{
ans+=arr[i]*fact(j);
ans = ans%1000003;
j++;
i--;
}
return ans+1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment