Left Rotate Array by One

Arrays Fundamentals Easy

Given an integer array nums, rotate the array to the left by one.


Note: There is no need to return anything, just modify the given array.

Examples:

Input: nums = [1, 2, 3, 4, 5]

Output: [2, 3, 4, 5, 1]

Explanation: Initially, nums = [1, 2, 3, 4, 5]

Rotating once to left -> nums = [2, 3, 4, 5, 1]

Input: nums = [-1, 0, 3, 6]

Output: [0, 3, 6, -1]

Explanation: Initially, nums = [-1, 0, 3, 6]

Rotating once to left -> nums = [0, 3, 6, -1]

Input: nums = [7, 6, 5, 4]

Constraints

  • 1 <= nums.length <= 105
  • -104 <= nums[i] <= 104

Hints

  • Focus on moving the first element of the array to the end while shifting all other elements one position to the left.
  • Think about how swapping or overwriting elements can achieve the desired rotation within the same array.

Company Tags

Walmart MongoDB Roche Roblox Seagate Technology Bungie Goldman Sachs Deloitte OYO Rooms Byju's Rakuten Visa Texas Instruments Etsy HCL Technologies Epic Systems NVIDIA Reddit DoorDash Teladoc Health PayPal Red Hat Zoho Robinhood Micron Technology TCS Cognizant Accenture Infosys Capgemini Wipro