Advertisement
Guest User

Sorted Permutation Rank

a guest
Oct 22nd, 2018
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.26 KB | None | 0 0
  1. class Solution:
  2.     def findRank(self, A):
  3.         alphabet = sorted(A)
  4.         ans = 0
  5.         for i,x in enumerate(A):
  6.             ans += alphabet.index(x) * math.factorial(len(A) - i - 1)
  7.             alphabet.remove(x)
  8.         return (ans + 1) % 1000003
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement