Count of subarrays of an Array having all unique digits | C # program to find the count of subarrays of an Array having all unique digits ; Function to check whether the subarray has all unique digits ; Storing all digits occurred ; Traversing all the numbers of v ; Storing all digits of v [ i ] ; Checking whether digits of v [ i ] have already occurred ; Inserting digits of v [ i ] in the set ; Function to count the number subarray with all digits unique ; Traverse through all the subarrays ; To store elements of this subarray ; Generate all subarray and store it in vector ; Check whether this subarray has all digits unique ; Increase the count ; Return the count ; Driver code
using System ; using System . Collections . Generic ; class GFG { static bool check ( List < int > v ) { HashSet < int > digits = new HashSet < int > ( ) ; for ( int i = 0 ; i < v . Count ; i ++ ) { HashSet < int > d = new HashSet < int > ( ) ; while ( v [ i ] > 0 ) { d . Add ( v [ i ] % 10 ) ; v [ i ] = v [ i ] / 10 ; } foreach ( int it in d ) { if ( digits . Contains ( it ) ) return false ; } foreach ( int it in d ) digits . Add ( it ) ; } return true ; } static int numberOfSubarrays ( int [ ] a , int n ) { int answer = 0 ; for ( int i = 1 ; i < ( 1 << n ) ; i ++ ) { List < int > temp = new List < int > ( ) ; for ( int j = 0 ; j < n ; j ++ ) { if ( ( i & ( 1 << j ) ) > 0 ) temp . Add ( a [ j ] ) ; } if ( check ( temp ) ) answer ++ ; } return answer ; } public static void Main ( String [ ] args ) { int N = 4 ; int [ ] A = { 1 , 12 , 23 , 34 } ; Console . Write ( numberOfSubarrays ( A , N ) ) ; } }