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
< ? php function digitProduct ( $ digits , $ start , $ end ) { $ pro = 1 ; for ( $ i = $ start ; $ i <= $ end ; $ i ++ ) { $ pro *= $ digits [ $ i ] ; } return $ pro ; } function isDistinct ( $ N ) { $ s = " $ N " ; $ len = sizeof ( $ s ) ; $ digits = array ( ) ; $ products = array ( ) ; for ( $ i = 0 ; $ i < $ len ; $ i ++ ) { $ digits [ $ i ] = $ s [ $ i ] - '0' ; } for ( $ i = 0 ; $ i < $ len ; $ i ++ ) { for ( $ j = $ i ; $ j < $ len ; $ j ++ ) { $ val = digitProduct ( $ digits , $ i , $ j ) ; if ( in_array ( $ val , $ products ) ) return false ; else array_push ( $ products , $ val ) ; } } return true ; } $ N = 324 ; if ( isDistinct ( $ N ) ) echo " YES " ; else echo " NO " ; ? >