⚡O(1) JAVA simple solution | 0ms | 100% faster
for eg: arr = [1,2,3,4,5] k=2, Now reverse the array. It becomes [5,4,3,2,1]\n2. Now split into two parts based on k value. like [5,4,] and [3,2,1]\n3. Now reve
1. for eg: arr = [1,2,3,4,5] k=2, Now reverse the array. It becomes [5,4,3,2,1]\n2. Now split into two parts based on k value. like [5,4,] and [3,2,1]\n3. Now reverse the both parts.\n```\nclass Solution {\n    public void rotate(int[] nums, int k) {\n        // step1: reverse the array\n        // step2: split the array into two.\n        // step3: reverse both the two parts.\n        \n        //taking k modulo for edge cases\n        k = k%nums.length;\n        swap(nums, 0, nums.length-1);\n        swap(nums, 0, k-1);\n        swap(nums, k, nums.length-1);\n    }\n    public void swap(int[] arr, int start, int end){\n        while(start<end){\n            int temp = arr[start];\n            arr[start] = arr[end];\n            arr[end] = temp;\n            start++;\n            end--;\n        }\n    }\n}\n\n```
['Array']