Maintained by Vikas Dulgunde, software engineer
You are given a string `s` made of English letters and single-space separators. The goal is to normalize its capitalization into title case.
For each word, the first character becomes uppercase and the rest of the word becomes lowercase, no matter what casing the input used. So `iPHONE` turns into `Iphone` and `the` turns into `The`.
Words are split by exactly one space, and that spacing is preserved in the output. Only the letter casing changes; the word boundaries stay where they were.
Return the transformed string.
Each word's first letter is capitalized and the remaining letters stay lowercase.
The all-caps input is rewritten so only the leading letter of each word stays uppercase.
Already correct words are left looking the same, and a mid-string capital like the start of a word is preserved while inner letters are lowercased.
Visible test cases
Title case is a per-word transformation. Can you split the string on spaces and handle each word on its own?
For one word, you need two pieces: the first character uppercased and everything after it lowercased. Slicing the word at index 1 gives you both halves.
Process the words, then join them back together with a single space so the original spacing is restored.
Treat the string as a list of words. Transform each word independently, then stitch the results back with spaces.
Scan the string once, tracking whether the current character is the first letter of a word. Capitalize it if so, lowercase it otherwise, and reset the flag at each space.