Detect and remove matched words in a char stream | Google Interview Question