You are given a string S containing only lowercase English alphabets. Your task is to count the number of distinct characters that appear more than once in the string.
If no character repeats (i.e., every character appears exactly once), you should print -1. Otherwise, print the count of distinct characters that have duplicates.
The first and only line of input contains a single string S.
If no character repeats, output a single integer -1.
Otherwise, output a single integer representing the count of distinct characters that appear more than once.
The count is of the characters themselves, not the total number of times they appear. For example, in the string "banana", the character 'a' repeats and the character 'n' repeats. The count of distinct repeating characters is 2.
The comparison is case-sensitive, but the input is guaranteed to be all lowercase alphabets.
programming
3
In the string "programming":
- 'r' appears 2 times.
- 'g' appears 2 times.
- 'm' appears 2 times.
- The other characters ('p', 'o', 'a', 'i', 'n') appear only once. The distinct characters that repeat are 'r', 'g', and 'm'. There are 3 such characters.
The expected time complexity for a single query is O(1) after an initial O(R * C) pre-computation. The total complexity is O(R * C).
unique
-1
The expected time complexity is O(N), where N is the length of the string S.
1 <= S.length <= 10^5
Time limit: 1 sec