FunctionRacerProblemsRace

Reverse Letters, Keep the Case Pattern

EasyStringsPython, JavaScript, TypeScript, Java, C++

s is a line of words made of letters, separated by single spaces (or the empty string). Reverse the letters of every word, but keep the pattern of uppercase and lowercase positions: a position that held an uppercase letter holds an uppercase letter afterwards, and a position that held a lowercase letter holds a lowercase letter. The words stay in their order and the spaces stay where they are.

For example "Hello World" becomes "Olleh Dlrow": Hello reversed is olleh, and because only the first position was uppercase the result is Olleh.

Example 1

s "Hello World"
returns "Olleh Dlrow"

Each word is reversed and then recased so the first letter stays uppercase and the rest lowercase.

Example 2

s "McDonald"
returns "DlAnodcm"

The pattern of McDonald is upper, lower, upper, then five lowercase; the reversed letters dlanodcm get that pattern.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Strings problems