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
- Number of even substrings in a string of digits
- Sum of all substrings of a string representing a number | Set 1
- Number of substrings with odd decimal value in a binary string
- Number of substrings divisible by 6 in a string of integers
- Given a binary string, count number of substrings that start and end with 1.
- Rearrange the string to maximize the number of palindromic substrings
- Count the number of vowels occurring in all the substrings of given string
- Sum of all substrings of a string representing a number | Set 2 (Constant Extra Space)
- 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
- Find the character in first string that is present at minimum index in second string
- Most frequent word in first String which is not present in second String
- Remove characters from the first string which are present in the second string
- Replace two substrings (of a string) with each other
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.