Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 51s1 days 16 hours 1 minutes 51 seconds.
Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 51s1 days 16 hours 1 minutes 51 seconds.

Sign in to watch this lesson
Advanced - Strings · 4:47
The Z-function stores, for every position, how much of the string starts again right there: the longest common prefix of s and the suffix at i. We compute it live for aaabaab with the rightmost match box [l, r), mirroring earlier values and clamping them to the box, show what goes wrong without the clamp on aaaabaa, and prove the scan linear because every successful comparison pushes r to the right. Then pattern search, borders and periods all fall out of one Z array.