I'm wondering why we need execute k %= (length of list). Should we return the ordinary list when k >= length? This is not a circular list.
Do anyone know what does the "rotate" mean? Thank you very much!
K%=length is done to save time , making the program efficient .
Assume length of list = 26 , k = 26 .
if we literally rotate the list 26 times , we would again regain the same list . So doing k = k%26 , gives k = 0. Hence , no rotation is done and list head is returned as it is .
Assume length of list = 26 , k = 28 .
So here , k=28 is same as k = k%26 , k = 2 , in disguise . So hence , only 2 shifts of elements in the list gives the answer.