0

This is left rotating array.Why it is not appending correctly, basically in first iteration it should append 3,4,5,1,2

Example input A = [1, 2, 3, 4, 5] B = [2, 3] Output: [ [3, 4, 5, 1, 2] [4, 5, 1, 2, 3] ] def reverse(a,left,right): #print(a) while right>left: a[left],a[right]=a[right],a[left] left+=1 right-=1 #print(a) return a class Solution: def solve(self, A, B): res=[] l=len(A) d=A for i in range(len(B)): # print(i) mod=B[i]%l # print(A) # print(d) reverse(d,mod,l-1) reverse(d,0,mod-1) reverse(d, 0, l-1) res.append(d) return res

9th Nov 2021, 6:44 AM
C Lover
3 ответов
+ 1
for n in B: C=A[::] for _ in range(n): C.push(C.pop()) print(C) Could be near to what u need
9th Nov 2021, 7:04 AM
Oma Falk
Oma Falk - avatar
0
Does it rotate or swap?
9th Nov 2021, 6:57 AM
Oma Falk
Oma Falk - avatar
0
What is A and B?
9th Nov 2021, 6:59 AM
Oma Falk
Oma Falk - avatar