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
- Print all Subsequences of String which Start with Vowel and End with Consonant.
- Number of substrings of a string
- Replace two substrings (of a string) with each other
- Number of substrings of one string present in other
- Count of substrings of a binary string containing K ones
- Split the string into substrings using delimiter
- Sum of all substrings of a string representing a number | Set 1
- Number of even substrings in a string of digits
- Lexicographical concatenation of all substrings of a string
- Program to print all substrings of a given string
- Meta Strings (Check if two strings can become same after a swap in one string)
- Number of substrings divisible by 6 in a string of integers
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.