Count array elements whose all distinct digits appear in K | Function to the count of array elements whose distinct digits are a subst of the digits of K ; Stores distinct digits of K ; Iterate over all the digits of K ; Insert current digit into st ; Update K ; Stores the count of array elements whose distinct digits are a subst of the digits of K ; Traverse the array , arr [ ] ; Stores current element ; Check if all the digits of arr [ i ] are present in K or not ; Iterate over all the digits of arr [ i ] ; Stores current digit ; If digit not present in the st ; Update flag ; Update no ; If all the digits of arr [ i ] present in st ; Update count ; Driver Code
def noOfValidKbers ( K , arr ) : NEW_LINE INDENT st = { } NEW_LINE while ( K != 0 ) : NEW_LINE INDENT if ( K % 10 in st ) : NEW_LINE INDENT st [ K % 10 ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT st [ K % 10 ] = st . get ( K % 10 , 0 ) + 1 NEW_LINE DEDENT K = K // 10 NEW_LINE DEDENT count = 0 NEW_LINE for i in range ( len ( arr ) ) : NEW_LINE INDENT no = arr [ i ] NEW_LINE flag = True NEW_LINE while ( no != 0 ) : NEW_LINE INDENT digit = no % 10 NEW_LINE if ( digit not in st ) : NEW_LINE INDENT flag = False NEW_LINE break NEW_LINE DEDENT no = no // 10 NEW_LINE DEDENT if ( flag == True ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT K = 12 NEW_LINE arr = [ 1 , 12 , 1222 , 13 , 2 ] NEW_LINE print ( noOfValidKbers ( K , arr ) ) NEW_LINE DEDENT