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
- Count the number of vowels occurring in all the substrings of given string
- Rearrange the string to maximize the number of palindromic substrings
- Given a binary string, count number of substrings that start and end with 1.
- Sum of all substrings of a string representing a number | Set 2 (Constant Extra Space)
- Find the character in first string that is present at minimum index in second string
- Remove characters from the first string which are present in the second string
- Most frequent word in first String which is not present in second String
- Count words present in a string
- Calculate sum of all numbers present in a string
- Find repeated character present first in a 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 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.