Last Updated: 31 Mar, 2025

Count Repeating Digits

Easy

Problem statement

You are given an integer 'N'.


Return the count of repeating digits in 'N'.


For Example :
Let 'N' = 9397776.
The repeating digits in 'N' are 9 and 7.
Therefore, the answer is 2.
Input Format :
The first line contains an integer 'N'.
Output Format :
Return the count of repeating digits in 'N'.
Note :
You don’t need to print anything. Just implement the given function.
Constraints :
0 <= 'N' <= 10^9

Time Limit: 1 sec

Approaches

01 Approach

Approach:

  • Create an array of size 10 to store the frequency of each digit (0-9).
  • Iterate through the digits of the number.
  • For each digit, increment its count in the frequency array.
  • Iterate through the frequency array and count the number of digits with a frequency greater than 1.

Algorithm:

  • Initialize an array 'freq' of size 10 with all elements as 0.
  • Convert the integer 'N' to a string 'S'.
  • Iterate using 'i' from 0 to length of 'S' - 1 :
    • Let 'digit' be the integer value of 'S[i]'.
    • Increment 'freq[digit]' by 1.
  • Initialize a variable 'count' to 0.
  • Iterate using 'i' from 0 to 9 :
    • If ( freq[i] > 1 ) :
      • Increment 'count' by 1.
  • Return 'count'.