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

What is phase balancing in OCPP Smart Charging?

Phase balancing with Ampcontrol

6 things I learned in 1337 coding school that made me a better developer

How to become a better Coder as an expert or a beginner

programming

WinjaCTF2021 “Secretive Flights” Challenge

The CTF Challenge

Develop Your First Web App — Tips and Tricks For Beginners

7 things you need to know, to ace your GSoC Proposal

Kotlin: when the null-safety is not safe with Spring Boot or Micronaut

DEBUGGING: The Developers Super Power

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

Hi all, attached below is the code demo for a Hackerrank that I recently attempted.

Everything you need to know about Python Lists- Part 2/2 (2022)

Datatypes in python and typecasting

Explain me this: Lists in Python + Cheatsheet