The problem is regarding reversing a list A of size N in groups of K. For example if A = [1,2,3,4,5]
, k = 3
Output = [3,2,1,5,4]
The error I get, when I run this is List Index out of range on line 4.
def reverseInGroups(A,N,K): arr1 = [] for i in range(K): arr1.append(A[(N-i)%K]) #line 4 for j in range(N-K): arr1.append(A[N-j-1]) return arr1