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’)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Minimum changes required to make first string substring of second string
- Find distinct characters in distinct substrings of a string
- Find minimum changes required in an array for it to contain k distinct elements
- Minimum flips required to form given binary string where every flip changes all bits to its right as well
- Distinct strings with odd and even changes allowed
- Count of substrings having all distinct characters
- Count of distinct substrings of a string using Suffix Trie
- Count of distinct substrings of a string using Suffix Array
- Generate a String of having N*N distinct non-palindromic Substrings
- Count distinct substrings of a string using Rabin Karp algorithm
- Count of Distinct Substrings occurring consecutively in a given String
- Minimum changes required such that the string satisfies the given condition
- Make a lexicographically smallest palindrome with minimal changes
- Minimum shifts of substrings of 1s required to group all 1s together in a given Binary string
- Generate a string whose all K-size substrings can be concatenated to form the given string
- Lexicographically smallest permutation of a string that contains all substrings of another string
- Count number of substrings with exactly k distinct characters
- Count distinct substrings that contain some characters at most k times
- Count number of distinct substrings of a given length
- Count of substrings of length K with exactly K distinct characters
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.