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

Sign in to watch this lesson
Advanced - Strings · 3:51
A string can hold a quadratic number of palindromes, but two arrays of radii, d_odd and d_even, describe them all. Interleaving # turns both kinds into odd palindromes so one array does the job, and Manacher's algorithm fills it in linear time by mirroring arcs inside the rightmost palindrome found so far and growing only past its edge. We trace #a#b#c#b#c#b#a# arc by arc, watch the right edge move only forward, and count palindromes in a long long.