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:
- Find the count of M character words which have at least one character repeated
- Given a binary string, count number of substrings that start and end with 1.
- Different substrings in a string that start and end with given strings
- Number of substrings that start with "geeks" and end with "for"
- Check if both halves of the string have at least one different character
- Minimize length of Substrings containing at least one common Character
- Program to build a DFA to accept strings that start and end with same character
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Maximize partitions such that no two substrings have any common character
- Count substrings that starts with character X and ends with character Y
- Count divisors of n that have at-least one digit common with n
- Number of substrings of one string present in other
- Shortest distance to every other character from given character
- Count pairs in an array such that frequency of one is at least value of other
- Print all Subsequences of String which Start with Vowel and End with Consonant.
- Minimum steps to reach end from start by performing multiplication and mod operations with array elements
- Count of subarrays which start and end with the same element
- Longest subsequence with at least one character appearing in every string
- Check if max occurring character of one string appears same no. of times in other
- Check if two strings can be made equal by swapping one character among each other
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.