human
Can you provide a code to check if an Array is a permutation of numbers from 1 to N : Set 2 and the other steps required given the following:
Check if an Array is a permutation of numbers from 1 to N : Set 2 | Function to check if an array represents a permutation or not.
Counting the frequency.
Check if each frequency is 1 only.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to check if an Array is a permutation of numbers from 1 to N : Set 2 and the other steps required.
 def permutation ( arr , N ) :
	hash = [ 0 ] * ( N + 1 ) ;
	for i in range ( N ) :
		hash [ arr [ i ] ] += 1 ;
	for i in range ( 1 , N + 1 ) :
		if ( hash [ i ] != 1 ) :
			return " No " ;
	return " Yes " ;
if __name__ == " _ _ main _ _ " :
	arr = [ 1 , 1 , 5 , 5 , 3 ] ;
	n = len ( arr ) ;
	print ( permutation ( arr , n ) ) ;