Fast C++ Solution | Good approach | Inbuilt Reverse
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n1) As Per Question if
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n1) As Per Question if Length of String is less than 2k then,\n        i) if less than k then reverse all\n        ii) else reveser first k\n\n2) if Length of String is greater than 2k then ,\ni) For Every 2k characters Reverse First K Characters.\nii) if Length is not Multiple of 2*k then lastly We have Characters less than 2k so Treat them as per Step 1.\n\n\n \n# Code\n```\nclass Solution {\npublic:\n    string reverseStr(string s, int k) {\n        \n        int len = s.length();\n        int n = 2*k;\n\n        if(len < n)\n        {\n            if(len < k)\n            {\n                reverse(s.begin(),s.end());\n                return s;\n            }\n            else\n            {\n                reverse(s.begin(),s.begin()+k);\n                return s;\n            }\n        }\n        else \n        {\n            int loop = len / n;\n            int a = 0;\n            int b = k;\n\n            for(int i=1;i<=loop;i++)\n            {\n                reverse(s.begin()+a,s.begin()+b);\n                a = 2*i*k;\n                b = a + k;\n            }\n\n            int rem = len % n;\n            if(rem == 0) return s;\n            \n            if(rem < k)\n            {\n                reverse(s.end() - rem ,s.end());\n            }\n            else\n            {\n                reverse(s.end() - rem ,s.end() - rem + k );\n            }\n\n            return s;\n        }\n    }\n};\n```\n# Upvote Me If You Like It\nA) If You\'re able to understand Solution Properly,then Please Upvote This Solution.\nB) If you still have any Doubt you Can ask anytime.\nC) Feedback and any Suggestion are highly appreciated.\n\n
['Two Pointers', 'String', 'C++']