solve reverse words problem