Microsoft Interview Question : Single Pass answer required

Anonymous User
242
Jun 30, 2022

Hi,

Find occurences of word in a string and print their indexes.(ignore special chars)

E.g.

String: Hi! How are you Hi?
Word: Hi

Ans: 0 4

This must be done in a single pass.

I converted all special chars into blanks and then used stringstream to get the words but the interviewer was not happy. It took 2 passes.

What should have been done ?

PS: It seems like such an easy question and yet I failed the interview.It is driving me crazy.

Comments (7)