Java Easy to Understand Solution with Explanation || 100% beats
Intuition\n> Considering reversing the array might lead you to a solution for this problem.\n\n# Approach\n1. First, it calculates the effective rotation amount
# Intuition\n> Considering reversing the array might lead you to a solution for this problem.\n\n# Approach\n1. First, it calculates the effective rotation amount by taking the modulus of k with the length of the array, ensuring that k is within the range of the array length.\n2. Then, it calls the reverse function three times:\n    - First, it reverses the entire array, effectively placing the last k elements at the start of the array.\n    - Second, it reverses the first k elements, moving them to the end of the array.\n    - Finally, it reverses the remaining elements, restoring the original order of the array with the elements rotated to the right by k steps.\n\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public void rotate(int[] nums, int k) {\n        k %= nums.length;\n        reverse(nums, 0, nums.length-1);\n        reverse(nums, 0, k-1);\n        reverse(nums, k, nums.length-1);\n    }\n\n    public void reverse(int[] nums, int start, int end){\n        while(start < end){\n            int temp = nums[start];\n            nums[start] = nums[end];\n            nums[end] = temp;\n            start++;\n            end--;\n        }\n    }\n}\n```\n\n![image.png](https://assets.leetcode.com/users/images/7563ffb2-b8e1-4eeb-80fd-83b42afd6a3e_1715710704.0413103.png)\n
['Array', 'Math', 'Two Pointers', 'Java']