human
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"
How can the above be solved in Python?
 ... Give me a code to count of subarrays of an Array having all unique digits and the other steps required?
assistant
#Here is code to count of subarrays of an Array having all unique digits and the other steps required.
 def check ( v ) :
	digits = set ( )
	for i in range ( len ( v ) ) :
		d = set ( )
		while ( v [ i ] != 0 ) :
			d . add ( v [ i ] % 10 )
			v [ i ] //= 10
		for it in d :
			if it in digits :
				return False
		for it in d :
			digits . add ( it )
	return True
def numberOfSubarrays ( a , n ) :
	answer = 0
	for i in range ( 1 , 1 << n ) :
		temp = [ ]
		for j in range ( n ) :
			if ( i & ( 1 << j ) ) :
				temp . append ( a [ j ] )
		if ( check ( temp ) ) :
			answer += 1
	return answer
if __name__ == " _ _ main _ _ " :
	N = 4
	A = [ 1 , 12 , 23 , 34 ]
	print ( numberOfSubarrays ( A , N ) )