You can find the problem details on HackerRank.
You are provided with a template in your chosen programming language; in this example, we use Python 3.
The problem requires returning the array with elements shifted to the left by d
positions. Note that while you will receive the length of the array as input, it is not explicitly needed to solve the problem.
Here is the Python code that solves the problem:
def rotateLeft(d, arr): return arr[d:] + arr[:d]
Explanation:
arr[d:]
slices the list from the d
-th element to the end.arr[:d]
slices the list from the beginning to the d
-th element.
We use cookies to improve your experience and analyze our traffic. By using our site, you consent to our use of cookies. You can manage your preferences below: