Easy to understand Java solution - Using 2 Priority queues
IntuitionThe goal is to simulate the orders executions with 2 backlogs. When there is a buy order, we need to find the sell order with the smallest price. The q
# Intuition

The goal is to simulate the orders executions with 2 backlogs. When there is a buy order, we need to find the sell order with the smallest price. The quickest way to find this would be by storeing the sell orders in a Priority queue, which is sorted by the price. 

Similarly, when there is a sell order, we need to find the buy order with the smallest price, which can be done using a PriorityQueue. 

So we use 2 Priority queues in the code and simulate buy/sell orders by iterating through the entire list.

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {

    class Order{
        int price;
        int amount;
        public Order(int price, int amount){
            this.price = price;
            this.amount = amount;
        }
    }

    public int getNumberOfBacklogOrders(int[][] orders) {
        PriorityQueue<Order> buyBacklog = new PriorityQueue<>( (a,b) -> Integer.compare(b.price, a.price) );
        PriorityQueue<Order> sellBacklog = new PriorityQueue<>( (a,b) -> Integer.compare(a.price, b.price) );
        for( int i = 0; i< orders.length ; i++){
            int price = orders[i][0];
            int amount = orders[i][1];
            int orderType = orders[i][2];

            if( orderType == 0){
                //BUy order
                while(!sellBacklog.isEmpty() && sellBacklog.peek().price <= price ){
                    Order sellOrder = sellBacklog.poll();
                    int remainingQty = sellOrder.amount;
                    
                    if( remainingQty < amount ){
                        amount-=remainingQty;
                    }else{
                        Order updatedSellOrder = new Order(sellOrder.price, remainingQty - amount);
                        amount = 0;
                        sellBacklog.offer( updatedSellOrder);
                        break;
                    }
                }

                if( amount > 0){
                    buyBacklog.offer( new Order( price, amount));
                }
            }else{
                //Sell order
                while( !buyBacklog.isEmpty() && buyBacklog.peek().price >= price){
                    Order buyOrder = buyBacklog.poll();
                    int remainingQty = buyOrder.amount;
                    if( remainingQty < amount ){
                        amount-=remainingQty;
                    }else{
                        Order updatedBuyOrder = new Order( buyOrder.price , remainingQty - amount);
                        amount =0;
                        buyBacklog.offer(updatedBuyOrder );
                        break;
                    }
                }
                if( amount > 0){
                    sellBacklog.offer( new Order(price, amount));
                }
            }
        }

        long totalOrdersRemaining = 0;
        while( !buyBacklog.isEmpty() ){
            totalOrdersRemaining+= buyBacklog.poll().amount;
        }
        
        while( !sellBacklog.isEmpty() ){
            totalOrdersRemaining+= sellBacklog.poll().amount;
        }

        return (int)(totalOrdersRemaining % (Math.pow(10, 9) + 7));
    }
}
```
['Java']