Length of longest subsequence in an Array having all elements as Nude Numbers | Function to check if the number is a Nude number ; Variable initialization ; Integer ' copy ' is converted to a string ; Total digits in the number ; Loop through all digits and check if every digit divides n or not ; flag is used to keep check ; Return true or false as per the condition ; Function to find the longest subsequence which contain all Nude numbers ; Find the length of longest Nude number subsequence ; Given array arr [ ] ; Function call
def isNudeNum ( n ) : NEW_LINE INDENT flag = 0 NEW_LINE copy = n NEW_LINE temp = str ( copy ) NEW_LINE length = len ( temp ) NEW_LINE for i in range ( length ) : NEW_LINE INDENT num = ord ( temp [ i ] ) - ord ( '0' ) NEW_LINE if ( ( num == 0 ) or ( n % num != 0 ) ) : NEW_LINE INDENT flag = 1 NEW_LINE DEDENT DEDENT if ( flag == 1 ) : NEW_LINE INDENT return False NEW_LINE DEDENT else : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT def longestNudeSubseq ( arr , n ) : NEW_LINE INDENT answer = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( isNudeNum ( arr [ i ] ) ) : NEW_LINE INDENT answer += 1 NEW_LINE DEDENT DEDENT return answer NEW_LINE DEDENT arr = [ 34 , 34 , 2 , 2 , 3 , 333 , 221 , 32 ] NEW_LINE n = len ( arr ) NEW_LINE print ( longestNudeSubseq ( arr , n ) ) NEW_LINE