Solution to Codeeval Reverse words problem