Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import factorial
- def find_rank(s):
- n = len(s)
- rank = 0
- chars = list(s)
- for i in range(n):
- count = 0
- for j in range(i + 1, n):
- if chars[j] < chars[i]:
- count += 1
- rank += count * factorial(n - i - 1)
- return rank + 1
- # Test Case
- print(find_rank("123456798")) # Output: 2
Advertisement
Add Comment
Please, Sign In to add comment