easy +8 pts

Capitalize First Letter

Transform a sentence so that the first letter of each word is uppercase and the rest lowercase.

Write a function `capitalize_first_letter(s: str) -> str` that takes a string `s` and returns a new string where the first letter of each word is uppercase and all other letters are lowercase. A word is defined as any sequence of non-space characters (spaces and punctuation are preserved as-is). The input string may contain leading/trailing spaces and multiple consecutive spaces. The function should work for any non-empty string, but may also be called with an empty string, in which case it returns an empty string. Implement the function exactly as specified.

Constraints

- `0 <= len(s) <= 10^5` - Input consists of printable ASCII characters.

Example

```python
>>> capitalize_first_letter("hello world")
'Hello World'
>>> capitalize_first_letter("heLLo WoRLD")
'Hello World'
>>> capitalize_first_letter("  hello   world  ")
'  Hello   World  '
>>> capitalize_first_letter("")
''
```
8 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use `str.split(' ')` to split on spaces, but be careful to preserve the original spacing.
A straightforward way is to iterate through the string and track whether you are at the start of a word.
Remember to handle the empty string case explicitly.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.