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 ; to maintain digit products ; Finding all possible subarrays ; Driver code
function digitProduct ( digits , start , end ) { let pro = 1 ; for ( let i = start ; i <= end ; i ++ ) { pro *= digits [ i ] ; } return pro ; } function isDistinct ( N ) { let s = " " ; let len = s . length ; let digits = new Array ( ) ; let products = new Array ( ) ; for ( let i = 0 ; i < len ; i ++ ) { digits [ i ] = s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; } for ( let i = 0 ; i < len ; i ++ ) { for ( let j = i ; j < len ; j ++ ) { let val = digitProduct ( digits , i , j ) ; if ( products . includes ( val ) ) return false ; else products . push ( val ) ; } } return true ; } let N = 324 ; if ( isDistinct ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;