Pergunta de entrevista da empresa Meta

search needle in haystack problem

Resposta da entrevista

Sigiloso

5 de abr. de 2012

But this can fail at some point.. void search(string needle, string hystack) { int cnt = 0, i, j; for(i = 0; i < hystack.size(); i++) { cnt = 0; if(hystack[i] == needle[0] && (i+needle.size()-1) < hystack.size()) { for(j = i; j < (i+needle.size()); j++) if(hystack[j] != needle[j-i]) break; else cnt++; } if(cnt == needle.size()) cout << true << endl; } }