Most optimized solution || C++ || O(N) - Time Complexity
Approach\n Describe your approach to solving the problem. \n\n  # Note: k might be greater than or equal to nums.size(). Therefore set k equal to k % nums.size(
# Approach\n<!-- Describe your approach to solving the problem. -->\n<div class="Note:">\n  <p><strong># Note:</strong> k might be greater than or equal to nums.size(). Therefore set k equal to k % nums.size() .</p>\n</div>\n\n<pre>\nk = k % nums.size();\n</pre>\n\n\n##### Example:- 1 2 3 4 5 6 7; k = 4; n = 7\n1. Reverse the k elements from the last:\n<pre>reverse(nums.end() - k, nums.end());      // 1 2 3 7 6 5 4</pre>\n2. Then reverse the elements form index 0 to n-k-1:\n<pre>reverse(nums.begin(), nums.end() - k);    // 3 2 1 7 6 5 4</pre>\n3. Now reverse the whole nums;\n<pre>reverse(nums.begin(), nums.end());        // 4 5 6 7 1 2 3</pre> \n\n\n<!-- <div class="Note:">\n  <p><strong># Note:</strong> k might be greater than or equal to nums.size(). Therefore set k equal to k % nums.size() .</p>\n</div> -->\n# Complexity\n\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\n# Code\n```\nclass Solution {\npublic:\n    void rotate(vector<int>& nums, int k) {\n        // int nums_size = nums.size();\n        k = k % nums.size();\n        if(k!=0)\n        {\n            reverse(nums.end() - k, nums.end());\n            reverse(nums.begin(), nums.end() - k);\n            reverse(nums.begin(), nums.end());\n        }\n    }\n};\n```\n\n### Please upvote!!!\n\n<!-- <p><img src="https://assets.leetcode.com/users/images/be16a9b6-6d5f-433f-89e8-90f18384d6f9_1683670956.5248532.jpeg" alt="7abc56.jpg"></p> -->
['Array', 'Iterator', 'C++']