← Back to challenges

Count the Number of Duplicate Characters

PythonHardstringsvalidationinterview

Instructions

Create a function that takes a string and returns the number of alphanumeric characters that occur more than once.

Examples

duplicate_count("abcde") ➞ 0

duplicate_count("aabbcde") ➞ 2

duplicate_count("Indivisibilities") ➞ 2

duplicate_count("Aa") ➞ 0
# Case sensitive

Notes

  • Duplicate characters are case sensitive.
  • The input string will contain only alphanumeric characters.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: String Flips