MCPcopy Create free account
hub / github.com/Abhishek-Saini/educational / prefix_function

Function prefix_function

cses/string/String_Functions.cpp:55–67  ·  view source on GitHub ↗

KMP LCP Array

Source from the content-addressed store, hash-verified

53
54// KMP LCP Array
55vector<int> prefix_function(string s) {
56 int n = (int) s.length();
57 vector<int> pi(n);
58 for (int i = 1; i < n; i++) {
59 int j = pi[i-1];
60 while (j > 0 && s[i] != s[j])
61 j = pi[j-1];
62 if (s[i] == s[j])
63 j++;
64 pi[i] = j;
65 }
66 return pi;
67}
68
69
70

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected