Best Solution in C++ for Arrays 🚀 || 100% working
Intuition 💡When rotating an array, the last k elements move to the front, and the rest shift to the back. This can be done using reversal tricks! 🚀Approach 🚶‍♂️
# Intuition 💡
When rotating an array, the last `k` elements move to the front, and the rest shift to the back. This can be done using **reversal tricks**! 🚀

# Approach 🚶‍♂️➡️🏃‍♂️
1. Reverse the entire array.
2. Reverse the first `k` elements.
3. Reverse the remaining elements.

It's just reversing! 🔄

# Complexity 🚦
- **Time complexity:** $$O(n)$$ (linear time for reversing).
- **Space complexity:** $$O(1)$$ (in-place modification).

# Code 🧑‍💻
```cpp
class Solution {
public:
    void rotate(vector<int>& nums, int k) {
        int n = nums.size();
        k = k % n;
        reverse(nums.begin(), nums.end());
        reverse(nums.begin(), nums.begin() + k);
        reverse(nums.begin() + k, nums.end());
    }
};
```
<img src="https://assets.leetcode.com/users/images/7b864aef-f8a2-4d0b-a376-37cdcc64e38c_1735298989.3319144.jpeg" alt="upvote" width="150px">

# Connect with me on LinkedIn for more insights! 🌟 Link in bio
['Array', 'Math', 'C++']