amankbps's blog

By amankbps, history, 10 months ago, In English

Is their any way to convert lps array to z array

  • Vote: I like it
  • +3
  • Vote: I do not like it

»
10 months ago, # |
  Vote: I like it +3 Vote: I do not like it
  1. Initialize the Z array with the same length as the LPS array and set Z = 0.
  2. For each index i from 1 to the length of the LPS array, set Z[i] = LPS[i] if i is not equal to the sum of LPS[i] and i. Otherwise, find the maximum value of LPS[j] such that j + LPS[j] = i, and set Z[i] to that maximum value.

Hope this helps :)