Pergunta de entrevista da empresa Nokia

A Coding question on replacing specified set of strings (Say 'X') in a given string input (Say 'Str') where we need to identify each instance of X in Str and replace with minimal time.