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
- Count of substrings of a binary string containing K ones
- Sum of all substrings of a string representing a number | Set 1
- Split the string into substrings using delimiter
- Lexicographical concatenation of all substrings of a string
- Number of substrings of one string present in other
- Program to print all substrings of a given string
- Number of even substrings in a string of digits
- Meta Strings (Check if two strings can become same after a swap in one string)
- Counting even decimal value substrings in a binary 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.