0% found this document useful (0 votes)
8 views2 pages

3 RD 2

Uploaded by

rineeth m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

3 RD 2

Uploaded by

rineeth m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 2

import operator

a=2
b=3
def permutation(lst):

# If lst is empty then there are no permutations


if len(lst) == 0:
return []

# If there is only one element in lst then, only


# one permuatation is possible
if len(lst) == 1:
return [lst]

# Find the permutations for lst if there are


# more than 1 characters

l = [] # empty list that will store current permutation

# Iterate the input(lst) and calculate the permutation


for i in range(len(lst)):
m = lst[i]

# Extract lst[i] or m from the list. remLst is


# remaining list
remLst = lst[:i] + lst[i+1:]

# Generating all permutations where m is first


# element
for p in permutation(remLst):
l.append([m] + p)
return l

def create(n):
s=''
for i in range(1,n+2):
s+='{}'.format(i)
return s
def decode(s):
op=[]
for i in s:
if(i=='I'):
op.append(operator.lt)
if(i=='D'):
op.append(operator.gt)
return op
s=str(input())
n=len(s)
i=create(n)
perm=permutation(list(i))
ind=0
dec=decode(s)
found=1
while(found):
listToStr = ' '.join(map(str, perm[ind]))
if(dec==[]):
print(i)
found=0
break
chk=0
k=str(i)
for j in range(n):
if(dec[j](k[j],k[j+1])):
chk+=1
if(chk==n):
print(i)
found=0
break
ind+=1

You might also like