Amazon | Phone Interview | Add Missing Spaces

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2024-08-20Added By Anonymous
Source: Link

Company: Amazon
Role: SDE II
Interview Stage: Phone Screen
Location: Seattle
Year: unknown

Original Post Content:

A recent deployment to your team's service to remove extra whitespaces from user provided strings before saving them to a database ended up removing all the spaces between words before saving to database.

We need to write a function to help recover this data. The function will receive a string as input representing a one sentence. The function should find the word boundaries that exist within the input string, and insert a single space between each word before returning the corrected string as an output.

Input: 'helpmeandaddspaces'
Output: 'help me and add'

Assumption: There will be a dictionary method that will return a word is valid or invalid. E.g., 'He' is a valid word

Comments