JS Fastest solution. No need to overthink.
Intuition\nAs long as we can control the \'end index\', we are good to go.\nUse Math.min() to detect the end of array, and pass it as the\nend index of last rou
# Intuition\nAs long as we can control the \'end index\', we are good to go.\nUse Math.min() to detect the end of array, and pass it as the\nend index of last round of swap.\nPlease upvote if you think this is helpful.\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n). String is immutable, we need an array to resolve this.\n\n# Code\n```\nvar reverseStr = function (s, k, arr = s.split(""), k2 = k * 2) {\n  for (let i = 0; i < arr.length - 1; i += k2) {\n    swap(i, Math.min(i + k - 1, arr.length - 1));\n  }\n  return arr.join("");\n\n  function swap(start, end) {\n    while (start < end) {\n      [arr[start], arr[end]] = [arr[end], arr[start]];\n      start++;\n      end--;\n    }\n  }\n};\n\n```
['JavaScript']