Hackwithinfy Solution 2021

Nice Permutation

Python

# codewindow.in
# nice permutation
# code in python

from itertools import permutations as p


n=int(input())

if n<4:
    print(0)

else:

    l=[i for i in range(1,n+1)]

    s=list(p(l))

    res=[]

    for k in s:
        rem=[]

        for j in k:
            rem.append(j%2)
        
        if rem[0]!=rem[1] or rem[-1]!=rem[-2]:
            continue 
        
        c=1
        for i in range(1,len(rem)-1):
            if  rem[i]==rem[i-1] or rem[i]==rem[i+1]:
                continue
            else:
                c=0
                break
        if c:
            res.append(k)
    print(len(res)%((10**9)+7))

#end

Follow us

Also Checkout

Leave a Comment

Your email address will not be published. Required fields are marked *