human
Count subarrays consisting of first K natural numbers in descending order | Function to count subarray having the decreasing sequence K to 1.
Traverse the array.
Check if required sequence is present or not.
Reset temp to k.
Return the count.
Driver Code.
Function Call"
How can the above be solved in Python?
assistant
#Here is code to count subarrays consisting of first K natural numbers in descending order and the other steps required.
 def CountSubarray ( arr , n , k ) :
	temp = k
	count = 0
	for i in range ( n ) :
		if ( arr [ i ] == temp ) :
			if ( temp == 1 ) :
				count += 1
				temp = k
			else :
				temp -= 1
		else :
			temp = k
			if ( arr [ i ] == k ) :
				i -= 1
	return count
if __name__ == " _ _ main _ _ " :
	arr = [ 1 , 2 , 3 , 7 , 9 , 3 , 2 , 1 , 8 , 3 , 2 , 1 ]
	N = len ( arr )
	K = 3
	print ( CountSubarray ( arr , N , K ) )