Count of non decreasing arrays of length N formed with values in range L to R | Java implementation of the approach ; Function to return the count of different arrays ; No such combination exists ; Arrays formed with single elements ; Driver code
class GFG { static int countSum ( int N , int L , int R ) { if ( L > R ) { return 0 ; } if ( N == 1 ) { return R - L + 1 ; } if ( N > 1 ) { return ( N - 2 ) * ( R - L ) + 1 ; } return 0 ; } public static void main ( String [ ] args ) { int N = 4 , L = 4 , R = 6 ; System . out . print ( countSum ( N , L , R ) ) ; } }