Google | Phone Screening | Replace bad words in a string under memory constrains
Anonymous User
2302

A machine coding round question from a Google Interview:

I have list of words that I say are bad words. I give you a string, you have to replace all the bad words in the string with '$'. Caveat is: Its possible that the string or even individual words in the string dont fit in memory.

Eg:

String Input: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua
Bad words: incididunt, adipiscing, consectetur
String Output: Lorem ipsum dolor sit amet, $ $ elit, sed do eiusmod tempor $ ut labore et dolore magna aliqua

Your memory is say only 2 bytes. So its not possible to load the string & the bad words in the program and then iterate & replace it. 

Design an algorithm to solve for this. You arent allowed to use a DB or any other external system. You're required to code whatever system you need to use.

I didnt get an optimal solution for this. Any ideas?

Comments (5)