You are viewing a single comment's thread. Return to all comments →
Wow! Lovely Solution.. But what if the direction of rotation is left?
I have given it a try, please let me know if I am wrong:
if(idx+rot <= arr.length) System.out.println(arr[idx+rot]); else System.out.println(arr[arr.length-(idx+rot)]);
Seems like cookies are disabled on this browser, please enable them to open this website
Circular Array Rotation
You are viewing a single comment's thread. Return to all comments →
Wow! Lovely Solution.. But what if the direction of rotation is left?
I have given it a try, please let me know if I am wrong:
if(idx+rot <= arr.length) System.out.println(arr[idx+rot]); else System.out.println(arr[arr.length-(idx+rot)]);