Showing posts with label drill for 214 shortest palindrome. Show all posts
Showing posts with label drill for 214 shortest palindrome. Show all posts

Monday, September 2, 2019

10 minute exercise - find longest common prefix and suffix in the string

Sept. 2, 2019

Introduction


It is a drill for hard level algorithm 214 shortest palindrome. What I like to do is to write  a blog to calculate longest common prefix and suffix for a string.

My drill 


a b c d a b c a
0 1 2 3 4 5 6 7
0 0 0 0 1 2 3 1 <- Lps Array (longest prefix suffix array)

For example, string a b c d a b c 
prefix: abc
suffix: abc

"abc" is longest common prefix and suffix, so the table should be updated

a b c d a b c 
0 1 2 3 4 5 6 <- index 
0 0 0 0 1 2 3 <- longest prefix and suffix 


Actionable Items


I think that it is important for me to practice more often the simple drills and therefore I can prepare to work on hard level algorithm.