Given a integer k and a sting str, the task is to count the number of distinct sub-strings such that each sub-string does not contain some specific characters more than k times. The specific characters are given as another string.
Input: str = “ababab”, anotherStr = “bcd”, k = 1
All valid sub-strings are “a”, “b”, “ab”, “ba” and “aba”
Input: str = “acbacbacaa”, anotherStr = “ycb”, k = 2
- Store characters of anotherStr in a boolean array of size 256 for quick lookip
- Traverse through all substrings of given string. For every substring, keep the count of illegal characters in anotherStr.
- If the count of these characters exceeds the value of k then break out of the inner loop.
- Else, store this sub-string in an hash table to keep distinct substrings.
Below is the implementation of the above approach:
- Count number of substrings with exactly k distinct characters
- Count of substrings which contains a given character K times
- Count substrings with each character occurring at most k times
- Count number of distinct substrings of a given length
- Count substrings with same first and last characters
- Count of distinct substrings of a string using Suffix Trie
- Count of distinct substrings of a string using Suffix Array
- Recursive solution to count substrings with same first and last characters
- Check whether count of distinct characters in a string is Prime or not
- Replace minimal number of characters to make all characters pair wise distinct
- String with k distinct characters and no same characters adjacent
- Minimum changes to a string to make all substrings distinct
- Queries for frequencies of characters in substrings
- Find number of substrings of length k whose sum of ASCII value of characters is divisible by k
- Remove characters that appear more than k times
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.