human
Chocolate Distribution Problem | Set 2 | Function to print minimum number of candies required.
Distribute 1 chocolate to each.
Traverse from left to right.
Traverse from right to left.
Initialize sum.
Find total sum.
Return sum.
Driver Code.
Given array.
Size of the given array"
How can the above be solved in Python?
assistant
#Here is code to chocolate Distribution Problem and the other steps required.
 def minChocolates ( A , N ) :
	B = [ 1 for i in range ( N ) ]
	for i in range ( 1 , N ) :
		if ( A [ i ] > A [ i - 1 ] ) :
			B [ i ] = B [ i - 1 ] + 1
		else :
			B [ i ] = 1
	for i in range ( N - 2 , - 1 , - 1 ) :
		if ( A [ i ] > A [ i + 1 ] ) :
			B [ i ] = max ( B [ i + 1 ] + 1 , B [ i ] )
		else :
			B [ i ] = max ( B [ i ] , 1 )
	sum = 0
	for i in range ( N ) :
		sum += B [ i ]
	print ( sum )
if __name__ == ' _ _ main _ _ ' :
	A = [ 23 , 14 , 15 , 14 , 56 , 29 , 14 ]
	N = len ( A )
	minChocolates ( A , N )