Rotation Array || Clockwise Rotation || Rotation Game || Time Complexity: O(n) & SC: O(1)
Intuition\n Describe your first thoughts on how to solve this problem. \nTo solve this question you just need to know: \nHow to reverse the array?\nEg:\nA0  A1 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo solve this question you just need to know: \n**How to reverse the array?**\nEg:\nA0  A1  A2  A3  A4  A5  A6  A7  A8  A9  A10 A11\n\nfor K = 5\nthe last 5 elements comes at the front (**observation 1**)\n\nAfter rotation of K times, exactly from back will come to front.\n\n\nA7  A8  A9  A10 A11   A0  A1  A2  A3  A4  A5  A6\n\\-------------------\\ \\--------------------------\\\n______  k __________   ___________N-K _____________\n\nrotation(arr, k){\n// 1. reverse the complete array\n reverse(0, n-1);\n// 2. reverse the first k elements\n reverse(0, k-1);\n// 3. reverse the remaining elements\n reverse(k, n-1);\n}\n\n\n**Extension of Problem:**\n**What if K > N??**\nfor this you just have to have 1 condition:\nif(k > n){\nk = K %  n; // do rotations for k > n, you will figure why i did this.\n}\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSolution contains three steps:-\n1. Reverse the complete array.\n2. Reverse first K elements.\n3. Reverse remaining elements.\n\n# Complexity\n- Time complexity: N/2 + K/2 + (n-k)/2 => N/2 +  K/2 + N/2 - K/2 => 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    \n    public void reverse(int []arr, int low, int high){\n        while(low < high){\n            int temp = arr[low];\n            arr[low] = arr[high];\n            arr[high] = temp;\n\n            low++;\n            high--;\n        }\n    }\n    \n    public void rotate(int[] nums, int k) {\n        int n = nums.length;\n        int start = 0;\n        int end = n-1;\n        if(k > n){\n            k = k%n;\n        }\n        //1. reversing the whole array\n        reverse(nums, start, end);\n \n\n        //2. reversing the k part\n        reverse(nums, start, k-1);\n\n        //3. reverse the remaining part\n        reverse(nums, k, end);\n\n    }\n}\n```
['Array']