human
Count of permutations of an Array having maximum MEXs sum of prefix arrays | To calculate the factorial.
To return the number of permutations of an array with maximum MEXs sum of prefix array.
Map to store the frequency of each element.
Running a loop from i = 0 to i < n.
If continuity breaks , then break the loop.
Considering choices available to be filled at this position , i . e . mp [ i ].
Decrement the count of remaining right elements.
Adding all permutations of the elements present to the right of the point where continuity breaks ..
Driver Code"
Solution in Python:
assistant
#Here is code to count of permutations of an Array having maximum MEXs sum of prefix arrays and the other steps required.
 def factorial ( n ) :
	res = 1
	for i in range ( 2 , n + 1 ) :
		res *= i
	return res
def countPermutations ( ar , n ) :
	mp = dict ( )
	ans = 1
	cnt = n
	for i in range ( n ) :
		if ( ar [ i ] in mp ) :
			mp [ ar [ i ] ] += 1
		else :
			mp [ ar [ i ] ] = 1
	for i in range ( n ) :
		if ( i not in mp ) :
			break
		ans = ( ans * mp [ i ] )
		cnt -= 1
	ans = ans * factorial ( cnt )
	return ans
arr = [ 1 , 0 , 1 ]
N = len ( arr )
print ( countPermutations ( arr , N ) )