⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 20m 12s17 days 22 hours 20 minutes 12 seconds.
⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 20m 12s17 days 22 hours 20 minutes 12 seconds.

Sign in to watch this lesson
Algorithms - Strings · 5:04
The prefix function stores, for every prefix of a string, the length of its longest border (a proper prefix that is also a suffix). We build it cell by cell for aabaaab, watch a mismatch fall back to the border of the border, and prove the loop linear with a meter that can only fall as far as it has risen. Knuth-Morris-Pratt is then just the prefix function of pattern + '#' + text: a deterministic O(n + m) matcher that reads the text once and can stream it.