Given a string str and a character X. The task is to find the total number of sub-strings that contain the character X at least once.
Input: str = “abcd”, X = ‘b’
“ab”, “abc”, “abcd”, “b”, “bc” and “bcd” are the required sub-strings.
Input: str = “geeksforgeeks”, X = ‘e’
Approach: Total number of sub-strings are n * (n + 1) / 2, among them only those sub-strings need to be counted which contain character X. Character X is present in those sub-strings from position of X to the length of the string. For each character before X this sub-string must be counted.
Below is the implementation of the above approach:
- Count substrings that starts with character X and ends with character Y
- Number of substrings with count of each character as k
- Count of substrings which contains a given character K times
- Count substrings with each character occurring at most k times
- Print Kth character in sorted concatenated substrings of a string
- Count substrings that contain all vowels | SET 2
- Count substrings with same first and last characters
- Count of substrings of a binary string containing K ones
- Count Substrings with equal number of 0s, 1s and 2s
- Count of total anagram substrings
- Count all Prime Length Palindromic Substrings
- Count number of distinct substrings of a given length
- Find the count of substrings in alphabetic order
- Count distinct substrings that contain some characters at most k times
- Count number of substrings with exactly k distinct characters
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.