human
Count of seats booked on each of the given N flights | Function to find the total of the seats booked in each of the flights.
Stores the resultant sequence.
Traverse the array.
Store the first booked flight.
Store the last booked flight.
Store the total number of seats booked in flights [ l , r ].
Add K to the flight L.
Subtract K from flight number R + 1.
Find the prefix sum of the array.
Print total number of seats booked in each flight.
Driver Code.
Given list of bookings.
Function Call"
How can the above be solved in Python?
assistant
#Here is code to count of seats booked on each of the given N flights and the other steps required.
 def corpFlightBookings ( Bookings , N ) :
	res = [ 0 ] * N
	for i in range ( len ( Bookings ) ) :
		l = Bookings [ i ] [ 0 ]
		r = Bookings [ i ] [ 1 ]
		K = Bookings [ i ] [ 2 ]
		res [ l - 1 ] = res [ l - 1 ] + K
		if ( r <= len ( res ) - 1 ) :
			res [ r ] = ( - K ) + res [ r ]
	for i in range ( 1 , len ( res ) ) :
		res [ i ] = res [ i ] + res [ i - 1 ]
	for i in range ( len ( res ) ) :
		print ( res [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
	bookings = [ [ 1 , 3 , 100 ] , [ 2 , 6 , 100 ] , [ 3 , 4 , 100 ] ]
	N = 6
	corpFlightBookings ( bookings , N )