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
def corpFlightBookings ( Bookings , N ) : NEW_LINE INDENT res = [ 0 ] * N NEW_LINE for i in range ( len ( Bookings ) ) : NEW_LINE INDENT l = Bookings [ i ] [ 0 ] NEW_LINE r = Bookings [ i ] [ 1 ] NEW_LINE K = Bookings [ i ] [ 2 ] NEW_LINE res [ l - 1 ] = res [ l - 1 ] + K NEW_LINE if ( r <= len ( res ) - 1 ) : NEW_LINE INDENT res [ r ] = ( - K ) + res [ r ] NEW_LINE DEDENT DEDENT for i in range ( 1 , len ( res ) ) : NEW_LINE INDENT res [ i ] = res [ i ] + res [ i - 1 ] NEW_LINE DEDENT for i in range ( len ( res ) ) : NEW_LINE INDENT print ( res [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT bookings = [ [ 1 , 3 , 100 ] , [ 2 , 6 , 100 ] , [ 3 , 4 , 100 ] ] NEW_LINE N = 6 NEW_LINE corpFlightBookings ( bookings , N ) NEW_LINE DEDENT