Reputation: 101
This code is for the Google codejam competition. The below code is compiling correctly on my PC and gives the correct result for the sample code. However it is showing runtime error whenever I try to run it on the google website. I have been messing with it for one hour and still have no idea what's wrong with it.
def reversort(reverList):
global totalScore
length = len(reverList)
score = 0
for i in range(length - 1):
minimum = reverList.index(min(reverList[i: ]))
tempList = reverList[i:minimum + 1]
tempList.reverse()
reverList[i: minimum + 1] = tempList
score += minimum - i + 1
totalScore.append(score)
if __name__ == "__main__":
t = int(input())
totalScore = []
rev = []
for i in range(t):
n = int(input())
apen = []
for j in range(n):
apen.append(int(input()))
reversort(apen)
print("Case #{}: {}".format(i+1,totalScore[i]))
rev.append(apen)
Upvotes: 0
Views: 578
Reputation: 26
try this
reverse = int(input())
for i in range(1, reverse + 1):
a = int(input())
b = list(map(int, input().split()))
out = 0
for index in range(a-1):
min_index = b.index(min(b[index:a]))
b[index: min_index + 1] = reversed(b[index: min_index + 1])
out += (min_index) - (index) + 1
print("Case #{}: {}".format(i, out))
Upvotes: 1