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
function isNudeNum ( n ) { let copy , length , flag = 0 ; copy = n ; let temp ; temp = copy . toString ( ) ; length = temp . length ; for ( let i = 0 ; i < length ; i ++ ) { let num = temp [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ; if ( num == 0 n % num != 0 ) { flag = 1 ; } } if ( flag == 1 ) return false ; else return true ; } function longestNudeSubseq ( arr , n ) { let answer = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( isNudeNum ( arr [ i ] ) ) answer ++ ; } return answer ; } let arr = [ 34 , 34 , 2 , 2 , 3 , 333 , 221 , 32 ] ; let n = arr . length ; document . write ( longestNudeSubseq ( arr , n ) ) ;