Multiple spaces
Input
normalize_whitespace(' Hello world ')
Output
Hello world
All extra spaces are collapsed to single spaces and trimmed.
Full lesson preview
Collapse all runs of whitespace into single spaces and trim ends.
Problem statement
Task
Examples
Input
normalize_whitespace(' Hello world ')
Output
Hello world
All extra spaces are collapsed to single spaces and trimmed.
Input
normalize_whitespace('line1\nline2\tline3')
Output
line1 line2 line3
Newlines and tabs are converted to single spaces between tokens.
Input format
Output format
Constraints
Samples
Input
normalize_whitespace('already clean')
Output
already clean
No change needed.