Copy-pasted text often carries stray spaces. Given s, return it with all spaces at the start and end removed and every run of one or more spaces between words reduced to a single space.
Examples
Input: s = " hello big world "
Output: "hello big world"
Input: s = "already tidy"
Output: "already tidy"
Constraints
0 <= len(s) <= 5000smay contain letters, digits, spaces and punctuation (no tabs or newlines)
Goals
- Remove leading and trailing whitespace
- Collapse repeated inner spaces to one
- Combine `split` and `join`