Suppose we are given a string s1, we need to the find total number of substring(including multiple occurrences of the same substring) of s1 which are present in string s2.
Input : s1 = aab s2 = aaaab Output :6 Substrings of s1 are ["a", "a", "b", "aa", "ab", "aab"]. These all are present in s2. Hence, answer is 6. Input :s1 = abcd s2 = swalencud Output :3
The idea is to consider all substrings of s1 and check if it present in s2.
- Number of substrings of a string
- Sum of all substrings of a string representing a number | Set 1
- Number of even substrings in a string of digits
- Number of substrings divisible by 6 in a string of integers
- Number of substrings with odd decimal value in a binary string
- Count the number of vowels occurring in all the substrings of given string
- Count number of substrings of a string consisting of same characters
- Split the binary string into substrings with equal number of 0s and 1s
- Given a binary string, count number of substrings that start and end with 1.
- Repeat substrings of the given String required number of times
- Rearrange the string to maximize the number of palindromic substrings
- Sum of all substrings of a string representing a number | Set 2 (Constant Extra Space)
- Minimum number of substrings the given string can be splitted into that satisfy the given conditions
- Number of Positions to partition the string such that atleast m characters with same frequency are present in each substring
- Find the longest sub-string which is prefix, suffix and also present inside the string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.