Check if any permutation of a number is divisible by 3 and is Palindromic | Function to check if any permutation of a number is divisible by 3 and is Palindromic ; Hash array to store frequency of digits of n ; traverse the digits of integer and store their frequency ; Calculate the sum of digits simultaneously ; Check if number is not divisible by 3 ; If more than one digits have odd frequency , palindromic permutation not possible ; Driver Code
function isDivisiblePalindrome ( n ) { var hash = Array ( 10 ) . fill ( 0 ) ; var digitSum = 0 ; while ( n ) { digitSum += n % 10 ; hash [ n % 10 ] ++ ; n = parseInt ( n / 10 ) ; } if ( digitSum % 3 != 0 ) return false ; var oddCount = 0 ; for ( var i = 0 ; i < 10 ; i ++ ) { if ( hash [ i ] % 2 != 0 ) oddCount ++ ; } if ( oddCount > 1 ) return false ; else return true ; } var n = 34734 ; isDivisiblePalindrome ( n ) ? document . write ( " " ) : document . write ( " " ) ;