Check if all sub | Function to calculate product of digits between given indexes ; Function to check if all sub - numbers have distinct Digit product ; Length of number N ; Digit array ; set to maintain digit products ; Finding all possible subarrays ; Driver Code
def digitProduct ( digits , start , end ) : NEW_LINE INDENT pro = 1 NEW_LINE for i in range ( start , end + 1 ) : NEW_LINE INDENT pro *= digits [ i ] NEW_LINE DEDENT return pro NEW_LINE DEDENT def isDistinct ( N ) : NEW_LINE INDENT s = str ( N ) NEW_LINE length = len ( s ) NEW_LINE digits = [ None ] * length NEW_LINE products = set ( ) NEW_LINE for i in range ( 0 , length ) : NEW_LINE INDENT digits [ i ] = int ( s [ i ] ) NEW_LINE DEDENT for i in range ( 0 , length ) : NEW_LINE INDENT for j in range ( i , length ) : NEW_LINE INDENT val = digitProduct ( digits , i , j ) NEW_LINE if val in products : NEW_LINE INDENT return False NEW_LINE DEDENT else : NEW_LINE INDENT products . add ( val ) NEW_LINE DEDENT DEDENT DEDENT return True NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 324 NEW_LINE if isDistinct ( N ) == True : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT DEDENT