Easy Approach 🔥|| Beasts 100% 😍|| 1ms👌 || StringBuilder
\n# Approach\n Describe your approach to solving the problem. \n- Using StringBuilder to easily make substring of each k elements of every 2k iteration in the s
\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Using StringBuilder to easily make substring of each k elements of every 2k iteration in the string. \n- Revesring the substring (of first k elemenets ), then append it to the output StringBuilder object.  \n- Appending the rest substring( of last k-1 elements ) to the output.\n# Complexity\n- Time complexity:    O(n)\n\n![image.png](https://assets.leetcode.com/users/images/e837eb9e-7f8d-415a-9246-235090e57a3f_1683297205.4248207.png)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n### Please - Upvote :) \uD83D\uDD25\n\n# Code\n```\nclass Solution {\n    public String reverseStr(String s, int k) {\n        int n = s.length();\n        StringBuilder sb = new StringBuilder(n);\n\n        for (int i = 0; i < n; i += 2*k) {\n            // Creating the separator for every iteration.\n            int j = Math.min(i + k, n);\n            // Substring to reverse first k elements\n            StringBuilder rev = new StringBuilder(s.substring(i, j));\n            rev.reverse();\n            sb.append(rev);\n            // Substring to append the rest elements.\n            int rem = Math.min(i + 2*k, n);\n            sb.append(s.substring(j, rem));\n        }\n        // Converting back the StringBuilder to String\n        return sb.toString();\n    }\n}\n```
['String', 'Java']