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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- 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
- Count characters to be shifted from the start or end of a string to obtain another string
- Print all Subsequences of String which Start with Vowel and End with Consonant.
- Count binary strings of length same as given string after removal of substrings "01" and "00" that consists of at least one '1'
- Append digits to the end of dupicate strings to make all strings in an array unique
- Check if a Palindromic String can be formed by concatenating Substrings of two given Strings
- Check if a palindromic string can be obtained by concatenating substrings split from same indices of two given strings
- Count substrings with different first and last characters
- Count substrings of same length differing by a single character from two given strings
- Check if concatenation of splitted substrings of two given strings forms a palindrome or not
- Generate a string whose all K-size substrings can be concatenated to form the given string
- Count of substrings of a string containing another given string as a substring
- Count strings that end with the given pattern
- Minimum characters to be deleted from the end to make given two strings equal
- Find strings that end with a given suffix
- Minimum number of substrings the given string can be splitted into that satisfy the given conditions
- Reverse the substrings of the given String according to the given Array of indices
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.