Duplicate Character Counter

Published on 14 May 2022 (Updated: 18 January 2024)

Welcome to the Duplicate Character Counter page! Here, you'll find a description of the project as well as a list of sample programs written in various languages.

This article was written by:


Although a one line solution for this problem is feasible, just as huge brute force solutions are, we should avoid both of these approaches. Instead, our goal should be to find a fine line between both, where the code is not bogged down but is largely readable and maintainable.


The code should return the count of all duplicate, case-sensitive, alphanumeric characters, that occur more than once in the given string. Characters should also be presented in the order in which they appear in the string. For instance, 'abba' should output 'a' as the first character that has a duplicate.


Every project in the Sample Programs repo should be tested. In this section, we specify the set of tests specific to Duplicate Character Counter. In order to keep things simple, we split up the testing as follows:

Duplicate Character Counter Valid Tests

Description Input Output
Sample Input: No Duplicates "hola" "No duplicate characters"
Sample Input: Routine "goodbyeblues" "o: 2"
"b: 2"
"e: 2"

Duplicate Character Counter Invalid Tests

Description Input
No Input  
Empty Input ""

All of these tests should output the following:

Usage: please provide a string