We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Swap Permutation
Swap Permutation
Sort by
recency
|
13 Discussions
|
Please Login in order to post a comment
found solution here https://www.tutorialspoint.com/program-to-find-number-of-sequences-after-adjacent-k-swaps-and-at-most-k-swaps-in-python but can't understand the idea behind the solution
any idea how to use inversion here?
This can be solved really simple without any model and training data. defective Takata airbags
Here is my solution in java, javascript, python, C, C++, Csharp HackerRank Swap Permutation Problem Solution
!/bin/python3
import os import sys
#
Complete the swapPermutation function below.
# def swapPermutation(n, k): # # Write your code here. # mod = 1000000007 s = [1] + [0] * k t = [1] + [0] * k for i in range(1, n): temp = sum(s[max(k - i, 0):k]) % mod for j in range(k, 0, -1): s[j] = (s[j] + temp) % mod if j > i: temp = (temp + s[j - i - 1] - s[j - 1]) % mod else: temp = (temp - s[j - 1]) % mod for j in range(k, 0, -1): t[j] = (t[j] + i * t[j - 1]) % mod return sum(s[k % 2::2]) % mod, sum(t) % mod
if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w')