KMP algorithm finds Longest common prefix which is also a suffix.

So like Z algorithm, if we concatenate pattern and text as pattern + ‘#’ + text (where # is not in character set) and find lps[] of KMP and check how many lps[] elements are equal to pattern size like z algorithm, will we get the answer?

e.g. text = aacabd and pat = ab

concatenated string = ab#aacabd

lps[] = 0 0 0 1 1 0 1 2 0

since one value is 2, it means the pattern is present in the text.

Can anyone tell me if it is wrong for some test case? I am finding it a bit difficult to use KMP after finding LPS and finding it a bit hard to understand Z values.