O(1) Space Solution with explaination and code with comments in c++
So the idea here is first we will reverse the entire array for example if the array was :[1,2,3,4,5,6,7] k=3\nnow after we reverse it entirely we it will become
So the idea here is first we will reverse the entire array for example if the array was :[1,2,3,4,5,6,7] k=3\nnow after we reverse it entirely we it will become :[7,6,5,4,3,2,1]\nnow what we can do is reverse the subarray containing first k elements so now it will become :\n[5,6,7,4,3,2,1]\nnow u can notice that the elements which should have been in front after k rotations aree now in their right place and now finally to get our answer simply we reverse the rest of the elements then we will get :\n[5,6,7,1,2,3,4]  this is our answer \n\nthis would be the code for this approach i hope guys will like it also it requires kinda 3 loops if any one has a solution to solve it in single iteration please do suggest Thankyou for viewing this below  I will be sharing the code for this with comments also please share any suggestions if you guys have any\n\n```\nclass Solution {\npublic:\n    void rev(vector <int> &nums,int k){\n        int s=0,e=k-1;\n        while(s<=e){\n            swap(nums[e],nums[s]);\n            s++;e--;\n        }\n    }\npublic:\n    void rotate(vector<int>& nums, int k) {\n        k=k%nums.size();//Calculating the appropriate size of k so as to prevent any index out of bounds\n        \n        reverse(nums.begin(),nums.end());// reversing the entire array\n        \n        rev(nums,k);// reversing first k elements of the array\n        \n        reverse(nums.begin()+k,nums.end());//reversing reset of the (nums.size()-k) elements of the array\n    }\n};\n```\nTime Complexity : O(n)\nSpace Complexity : O(1)\n\nThankyou !
['C']