Here we are just checking if there are two or more than 2 consecutive spaces are there, then only we need to remove that extra space.
But this program can fail in two cases,
- When there is only one space in string, that is string having only one character - space, but this issue can be resolved by trimming surrounding spaces.
- Second if there is space at the end of string, but that is already resolved in first case.
Might be some more dimensions to test the program code.
Thanks