Sequence Equation : HackerRank Solution in Python 3.

Solution in Python 3

Explanation:-

The given list p contains elements which are less than or equal to the length of p and greater than or equal to 1.

First, we will iterate from 1 to len(p)+1 through a variable i and store the index of i occurred in list p in a new list called indices.

In the for loop we iterate from 1 to len(p) +1 because range function commences iteration from 0 by default. Similarly we append p.index(i)+1 because the index of any list starts from 0.

Then we will declare a new empty list called ans.

ans = []

Following that, will iterate the elements of list indices through a variable ele and store the index of ele occurred in list p in the list ans.

we append p.index(ele)+1 because the index of any list starts from 0.

At the end we will return the list ans.

return ans

--

--

Shounak Lohokare

pretending to teach is one of the best way to learn.