We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
He is beginning from the second last index and decrementing progressively, copying the element at that index to the next index, which does the same as your approach - working from the last index through to the second index (which is 1) and copying the value at the preceeding index to the one the counter is at. Both methods perform a right rotation of the array elements from indices 1 to n-1, and both shall work if the value at the last index is stored in another variable and is copied to the first index after each rotation.
Cookie support is required to access HackerRank
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 →
It's the same thing brother
He is beginning from the second last index and decrementing progressively, copying the element at that index to the next index, which does the same as your approach - working from the last index through to the second index (which is 1) and copying the value at the preceeding index to the one the counter is at. Both methods perform a right rotation of the array elements from indices 1 to n-1, and both shall work if the value at the last index is stored in another variable and is copied to the first index after each rotation.