
Think about substrings of length one.
Let 'N' = 3, 'S' = "aac".
You can change characters at index 2 to some other character (1-based indexing).
Like 'S' = "abc".
All substrings of 'S' are "a", "b", "c", "ab", "bc", "abc", all of which are distinct.
So the answer is 1.
First-line contains an integer 'T', which denotes the number of test cases.
For every test case:-
First-line contains an integer 'N', denoting the length of the string 'S'.
Second-line contains the string 'S'.
For each test case, Return the minimum number of changes required to make all the substrings of the string distinct or return -1 if you can't make it.
You don’t need to print anything. Just implement the given function.
1 <= 'T' <= 10
1 <= 'N' <= 10^5
'S' consists only of lower case english alphabets
The Sum of 'N' overall test cases does not exceed 10^5.
Time Limit: 1 sec
Approach:-
Algorithm:-