Empleador activo
Getting requests one-by-one until you get "goodbye" that could appear anywhere within a string or be split between different requests.
Anónimo
My first solution was to check if last 7 bytes of previous request + the current one contains "goodbye", and if not keep the last 7 bytes, and go to the next one. That apparently wasn't good enough (extra 7 bytes of memory!). Took me a while to understand what they thought was wrong with it. The optimization is to keep matching character to character, and keep an int for the last one that matched, then continue matching from there, and reset to 0 if not matched. for (i=0; i < str.length; i++) { if (str.charAt(i) != "goodbye".charAt(lastMatch)) { lastMatch = 0; } else if (lastMatch == 6) { stop(); } else lastMatch++