Update 2.md

This commit is contained in:
Pragy Agarwal 2019-11-29 18:29:46 +05:30 committed by GitHub
parent 6ca41be67e
commit 872edc4dea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -109,12 +109,12 @@ $\dfrac{k}{(n-1)!}$ will give us the index of the first digit. Remove that digit
def get_perm(A, k):
perm = []
while A:
# get the index of current digit
div = factorial(len(A)-1)
i, k = divmod(k, div)
perm.append(A[i])
# remove handled number
del A[index]
# get the index of current digit
div = factorial(len(A)-1)
i, k = divmod(k, div)
perm.append(A[i])
# remove handled number
del A[index]
return perm
```
@ -125,9 +125,10 @@ Sorted Permutation Rank (Optional)
> Given S, find the rank of the string amongst its permutations sorted lexicographically.
Assume that no characters are repeated.
```python
```
Input : 'acb'
Output : 2
Explanation:
The order permutations with letters 'a', 'c', and 'b' :
abc
acb