DEV Community

Discussion on: Day-15 Reverse words in a string

Collapse
 
mridubhatnagar profile image
Mridu Bhatnagar • Edited

The test doesn't seem to be valid to me. Explaining below the reason.

The problem statement says - "Given an input string, reverse the string word by word." For them, string means "multiple words separated by space". Now, see the NOTE section. It says "A word is defined as a sequence of non-space characters."

The intent of the problem is to reverse each word present in the string. And the string contains multiple words. Here, you are testing it on only single word "god".

Correct input would be
Input - "god is kind"
Output - "kind is god"

Also, you would observe we are not reversing characters present in word. We are reversing the complete string.

I hope I have made it clear.

Collapse
 
jeyraam profile image
Jayaram K

Thanks for the clarification.After I converted the string into list,I was able to reverse it.Any suggestions for good books/links to start Datastructures& A for beginners?