← Back to challenges

Even and Odd Strings

PythonMediumstringsinterviewlanguage_fundamentalssorting

Instructions

Given a one word lowercase string txt, return another string such that even-indexed and odd-indexed characters are grouped and groups are space-separated.

Examples

even_odd_string("mubashir") ➞ "mbsi uahr"
# Letters at even indexes = "mbsi"
# Letters at odd indexes = "uahr"
# Join both strings with a space

even_odd_string("sample") ➞ "sml ape"

even_odd_string("airforce") ➞ "aroc ifre"

Notes

There will be no space in the given string.

python3
Loading editor…
⌘ ↡ to run
Walks through the solution with reasoning and edge cases.
Next: Word Numbers! β†’