MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / solve

Function solve

CPP/String/Z-Algorithm.cpp:1–28  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1void solve(string str,int n,vector<int>& arr){
2 int l = 0;
3 int r = 0;
4 arr[0] = 0;
5 for(int i = 1;i < n;i++){
6 if(i > r){
7 l = i;
8 r = i;
9 while(r < n && str[r] == str[r-l]){
10 r++;
11 }
12 arr[i] = r - l;
13 r--;
14 }else{
15 int k = i - l;
16 if((arr[k] + i) <= r){
17 arr[i] = arr[k];
18 }else{
19 l = i;
20 while(r < n && str[r] == str[r-l]){
21 r++;
22 }
23 arr[i] = r-l;
24 r--;
25 }
26 }
27 }
28}
29
30int zAlgorithm(string s, string p, int n, int m)
31{

Callers 1

zAlgorithmFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected