Problem Link:
My Solution Link:
https://www.codechef.com/viewsolution/32826020
See when you are storing list2. You will know your error, try printing list2 and check what it stored
just a minute late.
for j in range(1,l):
list1[j-1] = list1[j]
list1[l-1] = first
for k in range(l-1):
list2[k] = list2[k+1]
list2[0] = last
both the loops do the similar(small differences) thing thats where you are going wrong.
change one of them so that the iterator is decreasing. hope it will work