Java || 2 Priority Queues || 1ms Beats 90%
\nclass Order implements Comparable<Order> {\n    int price, amount, orderType;\n    Order(int price, int amount, int orderType) {\n        this.price = price;\
```\nclass Order implements Comparable<Order> {\n    int price, amount, orderType;\n    Order(int price, int amount, int orderType) {\n        this.price = price;\n        this.amount = amount;\n        this.orderType = orderType;\n    }\n    \n    @Override\n    public int compareTo(Order order) {\n        return this.price - order.price;\n    }\n}\n\nclass Solution {\n    static final int  BUY = 0, SELL = 1, mod = 1000000007;\n    public int getNumberOfBacklogOrders(int[][] orders) {\n        PriorityQueue<Order> sellBacklog = new PriorityQueue<>();\n        PriorityQueue<Order> buyBacklog = new PriorityQueue<>(Collections.reverseOrder());\n        for(int[] order: orders) {\n            int price = order[0], amount = order[1], orderType = order[2];\n            Order orderInstance = new Order(price, amount, orderType);\n            if(orderType == SELL) {\n                Order topBuy = buyBacklog.peek();\n                while(topBuy != null && \n                      topBuy.price >= orderInstance.price && \n                      orderInstance.amount > 0) {\n                    int buysRemaining = Math.max(0, topBuy.amount - orderInstance.amount);\n                    int orderRemainig = Math.max(0, orderInstance.amount - topBuy.amount);\n                    topBuy.amount = buysRemaining;\n                    if(buysRemaining == 0) {\n                        buyBacklog.poll();\n                    }\n                    orderInstance.amount = orderRemainig;    \n                    topBuy = buyBacklog.peek();\n                }\n                if(orderInstance.amount > 0) {\n                    sellBacklog.add(orderInstance);\n                }\n            } else {\n                Order topSell = sellBacklog.peek();\n                while(topSell != null && \n                      topSell.price <= orderInstance.price && \n                      orderInstance.amount > 0) {\n                    int sellsRemaining = Math.max(0, topSell.amount - orderInstance.amount);\n                    int orderRemaining = Math.max(0, orderInstance.amount - topSell.amount);\n                    topSell.amount = sellsRemaining;\n                    if(sellsRemaining == 0) {\n                        sellBacklog.poll();\n                    }\n                    orderInstance.amount = orderRemaining;\n                    topSell = sellBacklog.peek();\n                }\n                if(orderInstance.amount > 0) {\n                    buyBacklog.add(orderInstance);\n                }\n            }\n        }\n        int total = 0;\n        while(!sellBacklog.isEmpty()) {\n            Order sell = sellBacklog.poll();\n            total = (total + sell.amount) % mod;\n        }\n        while (!buyBacklog.isEmpty()) {\n            Order buy = buyBacklog.poll();\n            total = (total + buy.amount) % mod;\n        }\n        return total;\n    }\n}\n```
['Heap (Priority Queue)', 'Java']