Squeeze out spaces
Inputs
text is 0 to 24 characters: lowercase letters and spaces.
Your tasks
- Create an empty string
kept. - Use a loop over
text. Add each character tokeptunless it is a space. - Complete
removeSpacesso it returnskept. Return it, do not print it.
Example
With text = "a b c d", removeSpaces returns "abcd".
Rules
- Keep the other characters in their original order.
Test data
TEST DATA 1: text is "a b c d"
TEST DATA 2: text is ""
Practice focus
Text is just a list of characters, so everything you know about lists applies. String problems in interviews are array problems with letters.