Given a string str which contains only the characters x and y, the task is to count all the sub-strings that start and end with an x and have at least a single y.
Input: str = “xyyxx”
“xyyx” and “xyyxx” are the only valid sub-strings.
Input: str = “xyy”
- Create an array countX where countX[i] stores the total x from i to n – 1.
- Now, for every x in the string, find the first y that appears after this x.
- And update count = count + countX[indexOf(y)] because with this x as the starting index, all sub-strings will be valid that will end at any x after the found y.
- Return the count in the end.
Below is the implementation of the above approach:
- Count substrings that starts with character X and ends with character Y
- Number of substrings that start with "geeks" and end with "for"
- Different substrings in a string that start and end with given strings
- Given a binary string, count number of substrings that start and end with 1.
- Count all substrings having character K
- Program to build a DFA to accept strings that start and end with same character
- Count of substrings which contains a given character K times
- Number of substrings with count of each character as k
- Count substrings with each character occurring at most k times
- Maximize partitions such that no two substrings have any common character
- Print Kth character in sorted concatenated substrings of a string
- Modify the string such that every character gets replaced with the next character in the keyboard
- Find a string such that every character is lexicographically greater than its immediate next character
- Replace every character of string by character whose ASCII value is K times more than it
- Longest Common Prefix using Character by Character Matching
- Find the count of M character words which have at least one character repeated
- Count of strings possible by replacing two consecutive same character with new character
- Map every character of one string to another such that all occurrences are mapped to the same character
- Replace every character of a string by a different character
- Shortest distance to every other character from given character
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.