Amazon Interview Question
Software Engineer / DevelopersTeam: AWS
Country: United States
Interview Type: Phone Interview
One solution: read char by char, and count the "whitespaces". With this algo, amount of memory is not an issue.
We just can't count spaces because there can be multiple whitespaces between words, and there can other delimiters between words like comma, period, semi-colon etc.
So, one solution can be have a Finite State machine with may be like 2 states (READING_WORD, IN_DELIMITER) and calculate the state transition from IN_DELIMITER -> READING_WORD which should give number of words.
- aakash01 December 26, 2011