Check if all sub | C # program to check if all sub - numbers have distinct Digit product ; 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 ; List to maintain digit products ; Finding all possible subarrays ; Driver code
using System ; using System . Collections ; using System . Collections . Generic ; public class GFG { static int digitProduct ( int [ ] digits , int start , int end ) { int pro = 1 ; for ( int i = start ; i <= end ; i ++ ) { pro *= digits [ i ] ; } return pro ; } static bool isDistinct ( int N ) { string s = N . ToString ( ) ; int len = s . Length ; int [ ] digits = new int [ len ] ; ArrayList products = new ArrayList ( ) ; for ( int i = 0 ; i < len ; i ++ ) { digits [ i ] = s [ i ] - '0' ; } for ( int i = 0 ; i < len ; i ++ ) { for ( int j = i ; j < len ; j ++ ) { int val = digitProduct ( digits , i , j ) ; if ( products . Contains ( val ) ) return false ; else products . Add ( val ) ; } } return true ; } public static void Main ( ) { int N = 324 ; if ( isDistinct ( N ) ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } }