Given a string, find minimum number of changes to it so that all substrings of the string become distinct.
Input : str = "aab" Output : 1 If we change one instance of 'a' to any character from 'c' to 'z', we get all distinct substrings. Input : str = "aa" Output : 1
To make all substrings distinct, every character must be different. So we simply need to count number of repeated characters. If length of string is more than 26, then we cannot convert it into a string with all distinct substrings (Here we assume that string should contain only lower case characters, ‘a’ to ‘z’)
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Find distinct characters in distinct substrings of a string
- Count of distinct substrings of a string using Suffix Trie
- Count of distinct substrings of a string using Suffix Array
- Minimum number of substrings the given string can be splitted into that satisfy the given conditions
- Minimum steps to delete a string after repeated deletion of palindrome substrings
- Minimum changes required to make first string substring of second string
- Minimum number of deletions to make a string palindrome
- Insert minimum parantheses to make string balanced
- Count minimum swap to make string palindrome
- Minimum number of deletions to make a string palindrome | Set 2
- Minimum cost to make a string free of a subsequence
- Minimum number of additons to make the string balanced
- Minimum number of swaps to make two binary string equal
- Minimum number of replacements to make the binary string alternating | Set 2
- Minimum characters to be added at front to make string palindrome
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.