You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: string-algorithms.md
+25-1Lines changed: 25 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -655,8 +655,32 @@ int numberOfDiffSubstrings(vector<int> &lcp, string &s)
655
655
}
656
656
```
657
657
658
-
### Longest Common Substring
658
+
### (LCS) Longest Common Substring
659
+
660
+
https://codeforces.com/edu/course/2/lesson/2/5
661
+
659
662
```c++
663
+
/*
664
+
Can be done using DP there will be two states pointer i and pointer j and each transition will be constant checking if pointer are equal or not.
665
+
This will be O(N*M)
666
+
667
+
668
+
Idea is for a given s and t string: aabba and baba we append like aabba#baba now create suffix array and lcp array
669
+
a 2
670
+
a#baba 1
671
+
aabba#baba 1
672
+
aba 2
673
+
abba#baba 1
674
+
ba 2
675
+
ba#baba 1
676
+
baba 2
677
+
bba#baba 1
678
+
679
+
1/2 represents where the string is comming from 1 means its string s and 2 means its string 2.
680
+
This can be determined is suffix array ith element index is greater than s size
681
+
If both i and i+1 are from same string and lcp (i.e. common between i and i+1 here in code indexing is one minus because 0th element lcp doesn't exist)
682
+
LCP symbolises a potential Longest common substring.
0 commit comments