Count of non decreasing arrays of length N formed with values in range L to R | C ++ implementation of the approach ; Function to return the count of different arrays ; No such combination exists ; Arrays formed with single elements ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; 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 ; } } int main ( ) { int N = 4 , L = 4 , R = 6 ; cout << countSum ( N , L , R ) ; return 0 ; }