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.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Dynamic Programming
  4. Swap Permutation
  5. Discussions

Swap Permutation

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 9 Discussions, By:

recency

Please Login in order to post a comment

  • manjunathpy05
    6 days ago+ 0 comments

    !/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')

    nk = input().split()
    
    n = int(nk[0])
    
    k = int(nk[1])
    
    result = swapPermutation(n, k)
    
    fptr.write(' '.join(map(str, result)))
    fptr.write('\n')
    
    • fptr.close(
    0|
    Permalink
  • thecodingsoluti2
    2 months ago+ 0 comments

    Here is Swap Permutation problem solution - https://programs.programmingoneonone.com/2021/07/hackerrank-swap-permutation-problem-solution.html

    0|
    Permalink
  • maryjaynes673
    12 months ago+ 0 comments

    This is basically what I had, really liked your solution. lemon break up spell

    -3|
    Permalink
  • kristinelavo
    12 months ago+ 0 comments

    I do not understand this method , can anyone help me to figure out this ? Kerala vasiyam specialist in Coimbatore

    -2|
    Permalink
  • KariLowe
    2 years ago+ 0 comments

    This can be solved really simple without any model and training data. binding love spells

    -5|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy