We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Step 1: Pair the value with index as the function is X->X
Value-->Index3-->12-->21-->35-->44-->5
Step 2: Sort the pairs using value
Value-->Index1-->32-->23-->14-->55-->4
Step 3: Print the index
32154
I solved the problem using Python 3. Here is a bit more who are willing to use Python 3.
I used zipped list which can be achieved using zip(values,indexes) to make the pair of value and index. Then I sorted the zipped list using sorted(zipvariablename,key=lambda x: x[0]). Finally I print the all the indexes of the zipped variable.
Hope it helps!
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Security Function Inverses
You are viewing a single comment's thread. Return to all comments →
Let's explain solution for test case 3 2 1 5 4
Step 1: Pair the value with index as the function is X->X
Step 2: Sort the pairs using value
Step 3: Print the index
I solved the problem using Python 3. Here is a bit more who are willing to use Python 3. I used zipped list which can be achieved using zip(values,indexes) to make the pair of value and index. Then I sorted the zipped list using sorted(zipvariablename,key=lambda x: x[0]). Finally I print the all the indexes of the zipped variable.
Hope it helps!