JS || Solution by Bharadwaj
Code\n\nvar getNumberOfBacklogOrders = function (orders) {\n    var bq = new MaxPriorityQueue({ priority: (bid) => bid[0] });\n    var sq = new MinPriorityQueue
# Code\n```\nvar getNumberOfBacklogOrders = function (orders) {\n    var bq = new MaxPriorityQueue({ priority: (bid) => bid[0] });\n    var sq = new MinPriorityQueue({ priority: (bid) => bid[0] });\n    var backlog = [bq, sq];\n    orders.forEach(order => {\n        let [price, amount, type] = order;\n        if (type === 0) {\n            while (!sq.isEmpty() && amount > 0) {\n                var cur = sq.front().element;\n                if (cur[0] <= price) {\n                    if (amount <= cur[1]) {\n                        cur[1] -= amount;\n                        amount = 0;\n                        break;\n                    }\n                    else {\n                        amount -= cur[1];\n                        sq.dequeue();\n                    }\n                } else {\n                    break;\n                }\n            }\n\n            if (amount > 0) {\n                bq.enqueue([price, amount]);\n            }\n        }\n        else {\n            while (!bq.isEmpty() && amount > 0) {\n                var cur = bq.front().element;\n                if (cur[0] >= price) {\n                    if (amount <= cur[1]) {\n                        cur[1] -= amount;\n                        amount = 0;\n                        break;\n                    }\n                    else {\n                        amount -= cur[1];\n                        bq.dequeue();\n                    }\n                } else {\n                    break;\n                }\n            }\n            if (amount > 0) {\n                sq.enqueue([price, amount]);\n            }\n        }\n    });\n\n    var res = 0;\n    var mod = 1000000007;\n    while (!bq.isEmpty()) {\n        var cur = bq.front().element;\n        res = (res + cur[1]) % mod;\n        bq.dequeue();\n    }\n    while (!sq.isEmpty()) {\n        var cur = sq.front().element;\n        res = (res + cur[1]) % mod;\n        sq.dequeue();\n    }\n    return res;\n};\n```
['JavaScript']