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

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Strings problems