Arrays and Hashing Array basics
55. Left Rotate an Array by One
You are given an array of integers nums. Rotate it one place to the left and return it. Every element moves
one position toward the start of the array, and the first element moves to the last position.
Do it in place: change nums itself and use only O(1) extra memory. Every value stays in the array, and the
array keeps its length.
Example 1
Input: nums = [4, -7, 0, 9, 2]
[-7,0,9,2,4]Explanation: The elements from −7 to 2 each move one place to the left. The first element, 4, moves to the last position.
Example 2
Input: nums = [-1000000000, 5, 1000000000]
[5,1000000000,-1000000000]Explanation: 5 and 109 move one place to the left, and −109 moves from the front to the end.
Example 3
Input: nums = [8]
[8]Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ nums.length ≤ 105-109 ≤ nums[i] ≤ 109
Clarifying questions
What you would ask an interviewer before writing any code.