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

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Liquidity options for the Polkadot ecosystem

Service Health Checks, Alerts and a bit of Graphite Plotting

cells in the lungs heart kidneys liver and intestines in people with Covid-19.

xpath cheet sheet

Docker !! [ with practical of course ; )]

Give Access to storage account in azure- Automation through Powershell

Load balanced Asp.Net Core Application with Docker, MongoDB, and Redis — Pt.4

Make QRcode in just a Few Lines

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Shounak Lohokare

Shounak Lohokare

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

More from Medium

Welcome to the “First Program” in Python? #Python Series-4

4 of the Best Python Features

CaDS— Code and Data Society

Sorted Squared Array