Python easy to understand with comments (heaps)
A simple implmentation using Heaps (creds to ye15 for a guideline)\n\n\ndef getNumberOfBacklogOrders(self, orders: List[List[int]]) -> int:\n    buy_heap, sell_
A simple implmentation using Heaps (creds to ye15 for a guideline)\n\n```\ndef getNumberOfBacklogOrders(self, orders: List[List[int]]) -> int:\n    buy_heap, sell_heap = [], [] #max heap for buy order, min heap for sell orders\n    \n    for p, a, t in orders:\n        #sell order\n        if t:\n            #while the quantity of the sell order is not satisfied and there is a match\n            while a and buy_heap and -buy_heap[0][0] >= p:\n                #quantity of the best buy order avialable\n                buy_amount = buy_heap[0][1]\n                #if there is enough buy_amount, we can execute this sell order and exit the loop\n                if buy_amount > a:\n                    #assign new amount after sell order\n                    buy_heap[0][1] -= a\n                    a = 0\n                #there is not enough of the best buy order to execute the sell order\n                else:\n                    #remove the current buy order (alredy used) and work with the next best buy order\n                    heapq.heappop(buy_heap)\n                    #update the remaining sell order\n                    a -= buy_amount\n            #if the sell order is not fulfilled, add it to the sell backlog (sell heap)\n            if a > 0:\n                heapq.heappush(sell_heap, [p, a])\n        #buy order    \n        else:\n            #same idea for buy order\n            while a and sell_heap and sell_heap[0][0] <= p:\n                sell_amount = sell_heap[0][1]\n                if(sell_amount > a):\n                    sell_heap[0][1] -= a\n                    a = 0\n                else:\n                    heapq.heappop(sell_heap)\n                    a-=sell_amount\n            if(a > 0):\n                heapq.heappush(buy_heap, [-p, a])\n    \n    #return the remaining orders in the backlog\n    return sum(a for _, a in buy_heap+sell_heap) % (10**9 + 7)\n```
['Heap (Priority Queue)', 'Python']