Last Updated: 3 Jan, 2026

Duplicate Character Counter

Easy

Problem statement

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.


Input Format:
The first and only line of input contains a single string S.


Output Format:
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.


Note:
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.