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.
My solution was pretty simple, after trying looping over the array without success, I tried the most simplistic approach, dividing the array and then putting it all together, as the order doesn't change I just needed to extract the portion of items where d would be the "zero" index and append to it the rest of the array.
One line needed, python 3, O(n) complexity
defrotateLeft(d,arr):returnarr[d:]+arr[:d]
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Left Rotation
You are viewing a single comment's thread. Return to all comments →
My solution was pretty simple, after trying looping over the array without success, I tried the most simplistic approach, dividing the array and then putting it all together, as the order doesn't change I just needed to extract the portion of items where d would be the "zero" index and append to it the rest of the array. One line needed, python 3, O(n) complexity