Given a string s and two other strings begin and end, find the number of different substrings in the string which begin and end with the given begin and end strings.
Input : s = "geeksforgeeks" begin = "geeks" end = "for" Output : 1 Input : s = "vishakha" begin = "h" end = "a" Output : 2 Two different sub-strings are "ha" and "hakha".
Approach : Find all occurrences of string begin and string end. Store the index of each string in two different arrays. After that traverse through whole string and add one symbol per iteration to already seen sub-strings and map new strings to some non-negative integers. As the ends and beginnings of strings and different string of equal length are mapped to different numbers (and equal strings are mapped equally), simply count the number of necessary sub-strings of certain length.
- Given a binary string, count number of substrings that start and end with 1.
- Number of substrings that start with "geeks" and end with "for"
- Sub-strings that start and end with one character and have at least one other
- Program to build a DFA to accept strings that start and end with same character
- Number of substrings of a string
- Replace two substrings (of a string) with each other
- Print all Subsequences of String which Start with Vowel and End with Consonant.
- Lexicographical concatenation of all substrings of a string
- Program to print all substrings of a given string
- Sum of all substrings of a string representing a number | Set 1
- Number of even substrings in a string of digits
- Count of substrings of a binary string containing K ones
- Split the string into substrings using delimiter
- Number of substrings of one string present in other
- Meta Strings (Check if two strings can become same after a swap in one 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.