Amazon Interview Question

Write the code about eliminating extra space in the string. e.g "hello world" to "hello world"