Hackerrank | Sequence Equation
Explanation:
Find the index of the element in the array and then take the index value to find it's index.
Eg: Array 2 3 1
Index of 1 is 3
Find index of 3 which is 2
Add to new array
Index of 2 is 1
Find index of 1 which is 3
Add to new array
Repeat Steps
def permutationEquation(p):
new = []
for i in range(1, len(p)+1):
new.append(p.index(p.index(i) +1) +1)
return new
Comments
Post a Comment