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.
Curious why this solution in Python gets a runtime error for about half of the test cases - I am guessing it's something to do with there being an earlier potential exit point for the loop than simply (s < lenA) or that I shouldn't be using functions like index or min in the solution and instead stick to primitive operations. I'm pretty much a novice, so any advice would help:
definsertionSort(arr):# Write your code heremoves=0s=0a=arr[:]lenA=len(arr)-1whiles<lenA:p=a.index(min(a))a.pop(p)moves+=ps+=1returnmoves
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Insertion Sort Advanced Analysis
You are viewing a single comment's thread. Return to all comments →
Curious why this solution in Python gets a runtime error for about half of the test cases - I am guessing it's something to do with there being an earlier potential exit point for the loop than simply (s < lenA) or that I shouldn't be using functions like index or min in the solution and instead stick to primitive operations. I'm pretty much a novice, so any advice would help: