Given a string str, the task is to find the count of distinct characters in all the distinct sub-strings of the given string.
Input: str = “ABCA”
Distinct sub-strings Distinct characters A 1 AB 2 ABC 3 ABCA 3 B 1 BC 2 BCA 3 C 1 CA 2
Hence, 1 + 2 + 3 + 3 + 1 + 2 + 3 + 1 + 2 = 18
Input: str = “AAAB”
Approach: Take all possible sub-strings of the given string and use a set to check whether the current sub-string has been processed before. Now, for every distinct sub-string, count the distinct characters in it (again set can be used to do so). The sum of this count for all the distinct sub-strings is the final answer.
Below is the implementation of the above approach:
- Count distinct substrings that contain some characters at most k times
- Count number of substrings with exactly k distinct characters
- Find the number of strings formed using distinct characters of a given string
- Minimum changes to a string to make all substrings distinct
- Count of distinct substrings of a string using Suffix Trie
- Count of distinct substrings of a string using Suffix Array
- String with k distinct characters and no same characters adjacent
- Convert given string so that it holds only distinct characters
- Check whether count of distinct characters in a string is Prime or not
- Print all distinct characters of a string in order (3 Methods)
- Length of the smallest sub-string consisting of maximum distinct characters
- Replace minimal number of characters to make all characters pair wise distinct
- Count number of distinct substrings of a given length
- Find all distinct palindromic sub-strings of a given string
- Find total number of distinct years from a string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.