human
Count ways to select K array elements lying in a given range | Function to calculate factorial of all the numbers up to N.
Factorial of 0 is 1.
Calculate factorial of all the numbers upto N.
Calculate factorial of i.
Function to find count of ways to select at least K elements whose values in range [ L , R ].
Stores count of ways to select at leas K elements whose values in range [ L , R ].
Stores count of numbers having Value lies in the range [ L , R ].
Traverse the array.
Check if the array elements Lie in the given range.
Update cntNum.
Stores factorial of numbers upto N.
Calculate total ways to select at least K elements whose values Lies in [ L , R ].
Update cntWays.
Driver code"
Solution in Python:
 Write me a code to count ways to select K array elements lying in a given range and the other steps required?
assistant
#Here is code to count ways to select K array elements lying in a given range and the other steps required.
 def calculateFactorial ( N ) :
	fact = [ 0 ] * ( N + 1 )
	fact [ 0 ] = 1
	for i in range ( 1 , N + 1 ) :
		fact [ i ] = fact [ i - 1 ] * i
	return fact
def cntWaysSelection ( arr , N , K , L , R ) :
	cntWays = 0
	cntNum = 0
	for i in range ( 0 , N ) :
		if ( arr [ i ] >= L and arr [ i ] <= R ) :
			cntNum += 1
	fact = list ( calculateFactorial ( cntNum ) )
	for i in range ( K , cntNum + 1 ) :
		cntWays += fact [ cntNum ] // ( fact [ i ] * fact [ cntNum - i ] )
	return cntWays
if __name__ == " _ _ main _ _ " :
	arr = [ 12 , 4 , 6 , 13 , 5 , 10 ]
	N = len ( arr )
	K = 3
	L = 4
	R = 10
	print ( cntWaysSelection ( arr , N , K , L , R ) )