human
Distribution of candies according to ages of students | Function to check The validity of distribution.
Stroring the max age of all students + 1.
Stroring the max candy + 1.
creating the frequency array of the age of students.
Creating the frequency array of the packets of candies.
pointer to tell whether we have reached the end of candy frequency array.
Flag to tell if distribution is possible or not.
Flag to tell if we can choose some candy packets for the students with age j.
If the quantity of packets is greater than or equal to the number of students of age j , then we can choose these packets for the students.
Start searching from k + 1 in next operation.
If we cannot choose any packets then the answer is NO.
Driver code"
How can the above be solved in Python?

What is a code to distribution of candies according to ages of students and the other steps required?
assistant
#Here is code to distribution of candies according to ages of students and the other steps required.
 def check_distribution ( n , k , age , candy ) :
	mxage = max ( age ) + 1
	mxcandy = max ( candy ) + 1
	fr1 = [ 0 ] * mxage
	fr2 = [ 0 ] * mxcandy
	for j in range ( n ) :
		fr1 [ age [ j ] ] += 1
	for j in range ( k ) :
		fr2 [ candy [ j ] ] += 1
	k = 0
	Tf = True
	for j in range ( mxage ) :
		if ( fr1 [ j ] == 0 ) :
			continue
		flag = False
		while ( k < mxcandy ) :
			if ( fr1 [ j ] <= fr2 [ k ] ) :
				flag = True
				break
			k += 1
		k = k + 1
		if ( flag == False ) :
			Tf = False
			break
	if ( Tf ) :
		print ( " YES " )
	else :
		print ( " NO " )
age = [ 5 , 15 , 10 ]
candy = [ 2 , 2 , 2 , 3 , 3 , 4 ]
n = len ( age )
k = len ( candy )
check_distribution ( n , k , age , candy )