Print all unique digits present in concatenation of all array elements in the order of their occurrence | C ++ program for the above approach ; Function to print long unique elements ; Reverse the list ; Traverse the list ; Function which check for all unique digits ; Stores the final number ; Stores the count of unique digits ; Converting string to long longer to remove leading zeros ; Stores count of digits ; Iterate over the digits of N ; Retrieve the last digit of N ; Increase the count of the last digit ; Remove the last digit of N ; Converting string to long longer again ; Iterate over the digits of N ; Retrieve the last digit of N ; If the value of this digit is not visited ; If its frequency is 1 ( unique ) ; Mark the digit visited ; Remove the last digit of N ; Passing this list to print long the reversed list ; Function to concatenate array elements ; Stores the concatenated number ; Traverse the array ; Convert to equivalent string ; Concatenate the string ; Passing string to checkUnique function ; Driver Code ; Function call to prlong long unique digits present in the concatenation of array elements
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printUnique ( vector < long long > lis ) { reverse ( lis . begin ( ) , lis . end ( ) ) ; for ( long long i : lis ) cout << i << " ▁ " ; } void checkUnique ( string st ) { vector < long long > lis ; long long res = 0 ; long long N = stoll ( st ) ; vector < long long > cnt ( 10 , 0 ) , cnt1 ( 10 , 0 ) ; while ( N > 0 ) { long long rem = N % 10 ; cnt [ rem ] += 1 ; N = N / 10 ; } N = stoll ( st ) ; while ( N > 0 ) { long long rem = N % 10 ; if ( cnt1 [ rem ] == 0 ) { if ( cnt [ rem ] == 1 ) lis . push_back ( rem ) ; } cnt1 [ rem ] = 1 ; N = N / 10 ; } printUnique ( lis ) ; } void combineArray ( vector < long long > lis ) { string st = " " ; for ( long long el : lis ) { string ee = to_string ( el ) ; st = st + ee ; } checkUnique ( st ) ; } int main ( ) { vector < long long > arr = { 122 , 474 , 612 , 932 } ; combineArray ( arr ) ; return 0 ; }