100% Beats Solution || step by step explain || Fast Solution || Easy Solution ||
Abhiraj Pratap Singh\n\n---\n\n# UPVOTE IT....\n\n---\n\n\n\n---\n\n\n# Intuition\n Describe your first thoughts on how to solve this problem. \n- The goal of t
# Abhiraj Pratap Singh\n\n---\n\n# UPVOTE IT....\n\n---\n\n![Screenshot (47).png](https://assets.leetcode.com/users/images/7a5e3ab8-1cec-4aaa-9d2a-cbae7daa0e16_1704820504.9809742.png)\n\n---\n\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- The goal of this code is to reverse every k characters in a given string s. The revStr function is used to reverse a substring of the string between the indices first and last (exclusive). The reverseStr function uses this helper function to reverse substrings of length k in the input string s.\n\n---\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. The reverseStr function iterates through the string s in steps of 2*k (every 2k characters).\n2. For each iteration, it calls the revStr function to reverse the substring of length k starting from the current index i.\n3. The reversed substrings are then concatenated to obtain the final reversed string.\n4. The modified string is returned as the result.\n\n---\n\n\n# Complexity\n\n---\n\n\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n- **Time complexity: O ( N ) ,** The time complexity of the revStr function is O(k/2) = O(k) since it iterates through half of the substring. In the reverseStr function, we iterate through the string in steps of 2*k, so the overall time complexity is O(n), where n is the length of the input string s.\n\n---\n\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n- **Space complexity: The space complexity is O(1)** as the reversal is done in-place without using any additional space. The string s is modified in situ.\n\n---\n\n\n# Code\n```\nclass Solution {\npublic:\n    void revStr(string &s, int first , int last)\n    {\n        if(last>s.size()-1)\n            last=s.size();\n        int start=first;\n        int end=last-1;\n        while(start<end)\n        {\n            swap(s[start],s[end]);\n            start++;\n            end--;\n        }\n    }\n    string reverseStr(string s, int k) \n    {\n        for(int i=0;i<s.size();i=i+2*k)\n            revStr(s,i,i+k);\n        return s;\n    }\n};\n```\n\n---\n\n# if you like the solution please UPVOTE IT..........\n\n---\n\n![discord-discordgifemoji.gif](https://assets.leetcode.com/users/images/02076263-5e35-4250-b225-29be8f7c3a39_1704821640.4233613.gif)\n\n---\n\n\n![fucking-die-redditor-stupid-cuck-funny-cat.gif](https://assets.leetcode.com/users/images/a2e46e0e-e4bb-4163-942d-c5441324c67c_1704821646.3454661.gif)\n\n---\n\n
['Two Pointers', 'String', 'String Matching', 'C++']