human
Count of subarrays which forms a permutation from given Array elements | Function returns the required count.
Store the indices of the elements present in A [ ] ..
Store the maximum and minimum index of the elements from 1 to i ..
Update maxi and mini , to store minimum and maximum index for permutation of elements from 1 to i + 1.
If difference between maxi and mini is equal to i.
Increase count.
Return final count.
Driver Code"
Solution in Python:
assistant
#Here is code to count of subarrays which forms a permutation from given Array elements and the other steps required.
 def PermuteTheArray ( A , n ) :
	arr = [ 0 ] * n
	for i in range ( n ) :
		arr [ A [ i ] - 1 ] = i
	mini = n
	maxi = 0
	count = 0
	for i in range ( n ) :
		mini = min ( mini , arr [ i ] )
		maxi = max ( maxi , arr [ i ] )
		if ( maxi - mini == i ) :
			count += 1
	return count
if __name__ == " _ _ main _ _ " :
	A = [ 4 , 5 , 1 , 3 , 2 , 6 ]
	print ( PermuteTheArray ( A , 6 ) )