The simplest 4 line solution (0ms, 100%) [JAVA]
\npublic String reverseStr(String str, int k) {\n\tchar[] s = str.toCharArray();\n\n\tfor(int i = 0; i < s.length; i += 2 * k) {\n\t\tint left = i; // first cha
```\npublic String reverseStr(String str, int k) {\n\tchar[] s = str.toCharArray();\n\n\tfor(int i = 0; i < s.length; i += 2 * k) {\n\t\tint left = i; // first character of 2k characters \n\t\tint right = Math.min(i + k - 1, s.length - 1);  // calculate right element (last character of 2k characters), if (i + k) - 1 index > str.length(), than use (s.length) - 1 index => last one\n\t\tswap(s, left, right);\n\t}\n\n\treturn String.valueOf(s);\n}\n\n\nprivate void swap(char[] s, int l, int r) {\n\twhile (l < r) {\n\t\tchar temp = s[l];\n\t\ts[l++] = s[r];\n\t\ts[r--] = temp;\n\t}\n}\n```\n\nAlso you simplify main code to 4 lines:\n\n```\npublic String reverseStr(String str, int k) {\n    char[] s = str.toCharArray();\n    for(int i = 0; i < s.length; i += 2 * k) {\n        swap(s, i, Math.min(i + k - 1, s.length - 1));\n    }\n    return String.valueOf(s);\n}\n```
['Java']