human
What is a code to count array elements whose all distinct digits appear in K and the other steps required given the following:
Count array elements whose all distinct digits appear in K | Function to check a digit occurs in the digit of K or not.
Iterate over all possible digits of K.
If current digit equal to digit.
Update K.
Function to find the count of array elements whose distinct digits are a subset of digits of K.
Stores count of array elements whose distinct digits are subset of digits of K.
Traverse the array , [ ] arr.
Stores the current element.
Check if all the digits arr [ i ] is a subset of the digits of K or not.
Iterate over all possible digits of arr [ i ].
Stores current digit.
If current digit does not appear in K.
Update flag.
Update no.
If all the digits arr [ i ] appear in K.
Update count.
Finally print count.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to count array elements whose all distinct digits appear in K and the other steps required.
 def isValidDigit ( digit , K ) :
	while ( K != 0 ) :
		if ( K % 10 == digit ) :
			return True
		K = K // 10
	return False
def noOfValidNumbers ( K , arr , n ) :
	count = 0
	for i in range ( n ) :
		no = arr [ i ]
		flag = True
		while ( no != 0 ) :
			digit = no % 10
			if ( not isValidDigit ( digit , K ) ) :
				flag = False
				break
			no = no // 10
		if ( flag == True ) :
			count += 1
	return count
if __name__ == " _ _ main _ _ " :
	K = 12
	arr = [ 1 , 12 , 1222 , 13 , 2 ]
	n = len ( arr )
	print ( noOfValidNumbers ( K , arr , n ) )