You are viewing a single comment's thread. Return to all comments →
Just calculate the effective number of rotations d % n and then simply change the list accordingly. Simple Pythonic solution with O(1) complexity:
def rotate(a, r):
l = a[r:] + a[:r]
if __name__ == '__main__':
nd = input().split()
n = int(nd)
d = int(nd)
a = list(map(int, input().rstrip().split()))
r = d % n
why did you add '*' in print(*rotate(a,r))????
'*' here is unpacking the items of the list that is returned from rotate method.
for i in range(d):
Hy my logic is corrct I have checked it in python compiler using custom input but i am unable to return the output in hackerrank compiler. help me out here