Easy · Strings

Swap even odd

Given an ASCII string s, swap the characters at indices 0 and 1, 2 and 3, and so on (each even index with the index after it), leave a final unpaired character in place, and return the resulting string.

Examples

Example 1

{
  "s": "abcdef"
}

Output: "badcfe"

Example 2

{
  "s": "algorithm"
}

Output: "laogirhtm"

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Strings problems