Python 3   ||   9 lines,  w/ explanation
Here\'s the plan:\n1. Establish maxheap buy for buy orders and minheap sell for sell orders.\n2. Iterate through orders. Push each element onto the appropriate 
Here\'s the plan:\n1. Establish maxheap `buy` for buy orders and minheap `sell` for sell orders.\n2. Iterate through `orders`. Push each element onto the appropriate heap.\n3. During each iteration, peak at the heads of each list and determine whether they allow a transaction. If so, pop both heads, and if one has a positive amount after the transaction, push it back on its heap, and check the new heads (lather, rinse, repeat... `while`)\n4. After the iteration,`return`the sum of`amt`in the heaps.\n\n```\nclass Solution:\n    def getNumberOfBacklogOrders(self, orders: List[List[int]]) -> int:\n\n        buy,sell  = [], []                                                              # <-- 1\n\n        for price,amt,order in orders:                                                  # <-- 2\n            if order: heappush(sell, ( price, amt))                                     #\n            else    : heappush(buy , (-price, amt))                                     #\n            \n            while buy and sell and -buy[0][0] >= sell[0][0]:                            # <-- 3\n                                                                                        #\n                (buyPrice,buyAmt), (sellPrice,sellAmt) = heappop(buy), heappop(sell)    #\n                                                                                        #\n                if   buyAmt > sellAmt: heappush(buy , (buyPrice , buyAmt -sellAmt))     #\n                elif buyAmt < sellAmt: heappush(sell, (sellPrice, sellAmt- buyAmt))     #\n\n        return sum(amt for _,amt in buy+sell)% (1000000007)                             # <-- 4\n```\n[https://leetcode.com/problems/number-of-orders-in-the-backlog/submissions/870707453/](http://)\n\nI could be wrong, but I think that time complexity is *O*(*N*) and space complexity is *O*(*N*).
['Python3']