You are given a string s, which may contain words, extra spaces between words, and leading or trailing spaces.
Your task is to reformat the string to a "normalized" version. A normalized string has all its words separated by exactly one space, with no spaces at the beginning or end of the string.
The first line of input contains a single string s.
Print the reformatted string on a single line.
A "word" is defined as any sequence of non-space characters.
If the input string is empty or contains only spaces, the output should be an empty string.
Hello World
Hello World
The leading spaces, trailing spaces, and the multiple spaces between "Hello" and "World" are all collapsed into a single space separating the two words.
Programming is fun and challenging
Programming is fun and challenging
All extra whitespace is removed, leaving only single spaces between each word.
The expected time complexity is O(N), where N is the length of the string.
0 <= length of s <= 10^6
The string consists of letters and spaces.
Time limit: 1 sec
The expected time complexity is O(N), where N is the length of the string.