Count of unique digits in a given number N | C ++ program for the above approach ; Function that returns the count of unique digits of the given number ; Initialize a variable to store count of unique digits ; Initialize cnt array to store digit count ; Iterate through the digits of N ; Retrieve the last digit of N ; Increase the count of the last digit ; Remove the last digit of N ; Iterate through the cnt array ; If frequency of digit is 1 ; Increment the count of unique digits ; Return the count / of unique digit ; Driver Code ; Given array arr [ ] ; Function Call
#include <iostream> NEW_LINE using namespace std ; int countUniqueDigits ( int N ) { int res = 0 ; int cnt [ 10 ] = { 0 } ; while ( N > 0 ) { int rem = N % 10 ; cnt [ rem ] ++ ; N = N / 10 ; } for ( int i = 0 ; i < 10 ; i ++ ) { if ( cnt [ i ] == 1 ) { res ++ ; } } return res ; } int main ( ) { int N = 2234262 ; cout << countUniqueDigits ( N ) ; return 0 ; }