question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
longest-uploaded-prefix | ✅✅Faster || Easy To Understand || C++ Code | faster-easy-to-understand-c-code-by-__kr-w9ub | Array\n\n\nclass LUPrefix {\npublic:\n \n vector<int> arr;\n \n // longest will keep track of untill (longest - 1) we have got the longest uploaded | __KR_SHANU_IITG | NORMAL | 2022-10-01T17:41:19.515131+00:00 | 2022-10-01T17:41:19.515175+00:00 | 72 | false | * ***Array***\n\n```\nclass LUPrefix {\npublic:\n \n vector<int> arr;\n \n // longest will keep track of untill (longest - 1) we have got the longest uploaded prefix\n \n int longestt = 1;\n \n LUPrefix(int n) {\n \n arr.assign(n + 1, 0);\n }\n \n void upload(int video) {\... | 1 | 0 | ['Array', 'C', 'C++'] | 0 |
longest-uploaded-prefix | Java Solution | Small Code | java-solution-small-code-by-_thepassenge-znlk | \nclass LUPrefix {\n \n Set<Integer> set;\n int maxVideoPrefix = 0;\n \n public LUPrefix(int n) {\n set = new HashSet<>();\n }\n \n | _thepassenger | NORMAL | 2022-10-01T17:38:01.503506+00:00 | 2022-10-01T17:38:29.638836+00:00 | 51 | false | ```\nclass LUPrefix {\n \n Set<Integer> set;\n int maxVideoPrefix = 0;\n \n public LUPrefix(int n) {\n set = new HashSet<>();\n }\n \n public void upload(int video) {\n set.add(video);\n while(set.contains(maxVideoPrefix+1)) {\n maxVideoPrefix++;\n }\n }... | 1 | 0 | ['Java'] | 0 |
longest-uploaded-prefix | C++ || Set || Simple Explanation | c-set-simple-explanation-by-anis23-wi02 | Approach:\n\n keep storing the values in the set\n keep track of the max_length\n whenever we encounter the longest() function\n\t start from the last stored ma | anis23 | NORMAL | 2022-10-01T17:29:55.121117+00:00 | 2022-10-01T17:29:55.121155+00:00 | 48 | false | **Approach:**\n\n* keep storing the values in the set\n* keep track of the max_length\n* whenever we encounter the longest() function\n\t* start from the last stored max value\n\t* now keep increasing it to the number that has not been added yet\n* example:\n\t* let currently m = 3\n\t* set = {1,2,3,5,6,7,9}\n\t* becau... | 1 | 0 | ['C', 'Ordered Set'] | 0 |
longest-uploaded-prefix | 🤯 [Python] Made Easy | Pointer based approach | Explained | python-made-easy-pointer-based-approach-7wn8f | We maintain a pointer to return the longest prefix size. At start the pointer stays at 0, Since we know there cant be a 0 video, so the pointer stays at 0 until | ramsudharsan | NORMAL | 2022-10-01T16:49:55.320988+00:00 | 2022-10-01T16:49:55.321027+00:00 | 85 | false | We maintain a pointer to return the longest prefix size. At start the pointer stays at 0, Since we know there cant be a 0 video, so the pointer stays at 0 until the 1st video is uploaded. As soon as the 1st video gets uploaded, we increase the pointer till the end of the array or till it finds another 0.\n\n**Upvote if... | 1 | 0 | ['Python'] | 0 |
longest-uploaded-prefix | simple and clean solution using vector<bool> | simple-and-clean-solution-using-vectorbo-sxaa | \nclass LUPrefix {\npublic:\n vector<bool> v;\n int a=1;\n int b;\n LUPrefix(int n) {\n v.resize(n+1,false);\n b=n;\n }\n \n | aniketpawar | NORMAL | 2022-10-01T16:49:52.479031+00:00 | 2022-10-01T16:49:52.479066+00:00 | 24 | false | ```\nclass LUPrefix {\npublic:\n vector<bool> v;\n int a=1;\n int b;\n LUPrefix(int n) {\n v.resize(n+1,false);\n b=n;\n }\n \n void upload(int video) {\n v[video]=true;\n }\n \n int longest() {\n while(a<=b)\n {\n if(v[a]==false)break;\n ... | 1 | 0 | [] | 0 |
longest-uploaded-prefix | python solution faster 90% | python-solution-faster-90-by-dugu0607-llzc | class LUPrefix:\n\n def init(self, n: int):\n self.arr = [False] * n\n self.minTrue = -1\n \n\n def upload(self, video: int) -> None: | Dugu0607 | NORMAL | 2022-10-01T16:49:46.099505+00:00 | 2022-10-01T16:49:46.099531+00:00 | 45 | false | class LUPrefix:\n\n def __init__(self, n: int):\n self.arr = [False] * n\n self.minTrue = -1\n \n\n def upload(self, video: int) -> None:\n video -= 1\n self.arr[video] = True\n if self.minTrue == video - 1:\n while video + 1 < len(self.arr) and self.arr[video ... | 1 | 0 | ['Python'] | 0 |
longest-uploaded-prefix | Union Find | with concise comment | union-find-with-concise-comment-by-lucie-0pcs | \nclass LUPrefix {\npublic:\n const int OFFLINE = -1;\n const int MAIN_SERVER = 1;\n vector<int> root;\n vector<int> rank;\n LUPrefix(int n) {\n | lucienlo | NORMAL | 2022-10-01T16:37:02.371479+00:00 | 2022-10-01T16:42:22.178785+00:00 | 58 | false | ```\nclass LUPrefix {\npublic:\n const int OFFLINE = -1;\n const int MAIN_SERVER = 1;\n vector<int> root;\n vector<int> rank;\n LUPrefix(int n) {\n root = vector<int>(n+1, OFFLINE);\n rank = vector<int>(n+1, 1);\n }\n\n int find (const int i) {\n if (i == -1 || root[i] == i)\n ... | 1 | 0 | ['Union Find', 'C'] | 1 |
longest-uploaded-prefix | C++ | Vector | Easy & Short Solution | c-vector-easy-short-solution-by-shubhamr-suzw | \nclass LUPrefix {\n vector<int> mp;\n int i = 1;\n int len;\npublic:\n LUPrefix(int n) {\n mp.resize(n+1);\n len = n;\n }\n \n | shubhamrwt2001 | NORMAL | 2022-10-01T16:35:37.559486+00:00 | 2022-10-01T16:35:37.559518+00:00 | 29 | false | ```\nclass LUPrefix {\n vector<int> mp;\n int i = 1;\n int len;\npublic:\n LUPrefix(int n) {\n mp.resize(n+1);\n len = n;\n }\n \n void upload(int video) {\n mp[video] = 1;\n while( i <= len && mp[i] ){\n i++;\n }\n }\n \n int longest() {\n ... | 1 | 0 | ['C'] | 0 |
longest-uploaded-prefix | Java | Easy Understanding | java-easy-understanding-by-singhmohit971-4mg1 | Hi Family,\n\nI did this question using Array\n\n\nclass LUPrefix {\n \n // declare the array\n int ar[];\n int max_cnt = 1;\n\n public LUPrefix( | singhmohit9718 | NORMAL | 2022-10-01T16:29:09.465604+00:00 | 2022-10-01T16:29:09.465640+00:00 | 44 | false | Hi Family,\n\nI did this question using Array\n\n```\nclass LUPrefix {\n \n // declare the array\n int ar[];\n int max_cnt = 1;\n\n public LUPrefix(int n) {\n //initialize the array\n ar = new int[n+2];\n }\n \n public void upload(int video) {\n ar[video] = 1;\n // ch... | 1 | 0 | ['Array', 'Java'] | 0 |
longest-uploaded-prefix | Simple Java solution | simple-java-solution-by-damingqisheng-kort | \nclass LUPrefix {\n boolean[] videos;\n int pointer = 0;\n public LUPrefix(int n) {\n videos = new boolean[n+1];\n }\n \n public void | damingqisheng | NORMAL | 2022-10-01T16:28:17.204611+00:00 | 2022-10-01T16:28:17.204651+00:00 | 30 | false | ```\nclass LUPrefix {\n boolean[] videos;\n int pointer = 0;\n public LUPrefix(int n) {\n videos = new boolean[n+1];\n }\n \n public void upload(int video) {\n videos[video] = true;\n }\n \n public int longest() {\n while(pointer < videos.length-1 && videos[pointer+1]) {\... | 1 | 0 | ['Array', 'Java'] | 0 |
longest-uploaded-prefix | Python UnionFind | python-unionfind-by-yeung9613-2oza | Expand size of neighbors if they are at least 1. longest() just returns the size of parent of 0.\n\nTime:\n- upload: amortized O(1)\n- longest: amortized O(1)\n | yeung9613 | NORMAL | 2022-10-01T16:27:17.406751+00:00 | 2022-10-01T19:18:25.755779+00:00 | 110 | false | Expand size of neighbors if they are at least 1. longest() just returns the size of parent of 0.\n\nTime:\n- upload: amortized O(1)\n- longest: amortized O(1)\n\nSpace: O(n)\n\n```python\nclass UF:\n def __init__(self, n):\n self.parents = [i for i in range(n)]\n self.size = [0] * n\n \n def ... | 1 | 0 | ['Union Find', 'Python'] | 0 |
longest-uploaded-prefix | Easy to understand using array. | easy-to-understand-using-array-by-kamal0-sus4 | \nclass LUPrefix:\n\n def __init__(self, n: int):\n self.i = 0\n self.l = [0]*(n+1)\n self.n = n\n\n def upload(self, video: int) -> | kamal0308 | NORMAL | 2022-10-01T16:19:42.042572+00:00 | 2022-10-01T16:25:41.568663+00:00 | 28 | false | ```\nclass LUPrefix:\n\n def __init__(self, n: int):\n self.i = 0\n self.l = [0]*(n+1)\n self.n = n\n\n def upload(self, video: int) -> None:\n if video==1:\n self.i = 1\n self.l[video]=1\n while(self.i<self.n):\n if self.l[self.i+1]==1:\n ... | 1 | 1 | ['Python', 'Python3'] | 0 |
longest-uploaded-prefix | c++, Very easy, O(n) | c-very-easy-on-by-chaser_aim-mjui | \'\'\'\nThe key point here is to increase the value uploaded prefix whenever we are getting continuous number.\n \n vector v;\n int ans = 0;\n LUPre | chaser_aim | NORMAL | 2022-10-01T16:18:19.009209+00:00 | 2022-10-30T09:30:26.786390+00:00 | 39 | false | \'\'\'\nThe key point here is to increase the value uploaded prefix whenever we are getting continuous number.\n \n vector<bool> v;\n int ans = 0;\n LUPrefix(int n) {\n\t\n\t\t// defining a vector of size 1 greater n;\n v.resize(n + 1);\n for(int i = 0;i <n; i++){\n\t\t\n\t\t// false means the... | 1 | 0 | ['C'] | 0 |
longest-uploaded-prefix | Java | Set and Union Find | Easy explanation ✅ | java-set-and-union-find-easy-explanation-eswh | Terminology\nLet\'s call a contiguous section of videos a component.\nEx: [1,2,4,5,6,8,9]\nComponents: [1,2], [4,5,6], [8,9]\n\n#### Logic:\n Keep a set for see | Saumay_Khandelwal | NORMAL | 2022-10-01T16:15:43.624997+00:00 | 2022-10-01T16:28:53.232456+00:00 | 117 | false | #### Terminology\nLet\'s call a contiguous section of videos a component.\nEx: [1,2,4,5,6,8,9]\nComponents: [1,2], [4,5,6], [8,9]\n\n#### Logic:\n* Keep a set for seen elements.\n* Maintain a union find set with n+1 elements\n\t* Larger root will become the root while doing union operation. Thus, root of an element wou... | 1 | 0 | ['Union Find', 'Ordered Set', 'Java'] | 0 |
longest-uploaded-prefix | Java Priority Queue Solution | java-priority-queue-solution-by-abascus-z3tf | \nclass LUPrefix {\n \n PriorityQueue<Integer> pq;\n int previousValue;\n\n public LUPrefix(int n) {\n pq = new PriorityQueue<>();\n p | abascus | NORMAL | 2022-10-01T16:10:57.910988+00:00 | 2022-10-01T16:10:57.911029+00:00 | 34 | false | ```\nclass LUPrefix {\n \n PriorityQueue<Integer> pq;\n int previousValue;\n\n public LUPrefix(int n) {\n pq = new PriorityQueue<>();\n previousValue = 0;\n }\n \n public void upload(int video) {\n pq.offer(video);\n \n while(!pq.isEmpty() && pq.peek().equals(prev... | 1 | 0 | [] | 0 |
longest-uploaded-prefix | Easiest Solution Ever C++ | easiest-solution-ever-c-by-rishabhsingha-ogws | \nclass LUPrefix {\n vector<int> ds;\n int count = 1;\n int len;\npublic:\n LUPrefix(int n) {\n len = n;\n ds = vector<int>(n+1);\n | Rishabhsinghal12 | NORMAL | 2022-10-01T16:09:18.028515+00:00 | 2022-10-01T16:12:52.895399+00:00 | 42 | false | ```\nclass LUPrefix {\n vector<int> ds;\n int count = 1;\n int len;\npublic:\n LUPrefix(int n) {\n len = n;\n ds = vector<int>(n+1);\n }\n \n void upload(int video) \n {\n if(video == count)\n {\n ds[video]++;\n count++;\n video++;\n ... | 1 | 0 | ['C', 'C++'] | 0 |
longest-uploaded-prefix | C++ || Easy || Similar to Find Mes number in Array problem | c-easy-similar-to-find-mes-number-in-arr-3k80 | \tclass LUPrefix {\n\tpublic:\n\t\tset st;\n\t\tunordered_map mp;\n\t\tLUPrefix(int n) \n\t\t{\n\t\t\tst.insert(1);\n\t\t}\n\n\t\tvoid upload(int video) \n\t\t{ | _Falcon | NORMAL | 2022-10-01T16:08:38.193381+00:00 | 2022-10-01T16:13:49.101010+00:00 | 28 | false | \tclass LUPrefix {\n\tpublic:\n\t\tset<long long> st;\n\t\tunordered_map<int, int> mp;\n\t\tLUPrefix(int n) \n\t\t{\n\t\t\tst.insert(1);\n\t\t}\n\n\t\tvoid upload(int video) \n\t\t{\n\t\t\tif (!mp[video + 1])\n\t\t\t{\n\t\t\t\tst.insert(video + 1);\n\t\t\t}\n\t\t\tst.erase(video);\n\t\t\tmp[video]++;\n\t\t}\n\n\t\tint ... | 1 | 0 | [] | 0 |
longest-uploaded-prefix | Easy solution | C++ | easy-solution-c-by-__abcd-w9g7 | solution 1:\n\nclass LUPrefix {\npublic:\n int len = 1, a[100001] = {0};\n LUPrefix(int n) {}\n void upload(int video) {\n a[video] = 1;\n | __Abcd__ | NORMAL | 2022-10-01T16:04:43.081259+00:00 | 2022-10-01T17:52:40.954194+00:00 | 26 | false | **solution 1:**\n```\nclass LUPrefix {\npublic:\n int len = 1, a[100001] = {0};\n LUPrefix(int n) {}\n void upload(int video) {\n a[video] = 1;\n while(a[len])++len;\n }\n \n int longest() {\n return len-1;\n }\n};\n\n/**\n * Your LUPrefix object will be instantiated and called... | 1 | 0 | [] | 0 |
longest-uploaded-prefix | Easy Java Solution | easy-java-solution-by-sumitk7970-ywxc | ```\nclass LUPrefix {\n boolean[] uploaded;\n int lPrefix = 0;\n\n public LUPrefix(int n) {\n uploaded = new boolean[n+1];\n }\n \n pub | Sumitk7970 | NORMAL | 2022-10-01T16:01:14.910856+00:00 | 2022-10-01T16:09:41.242343+00:00 | 102 | false | ```\nclass LUPrefix {\n boolean[] uploaded;\n int lPrefix = 0;\n\n public LUPrefix(int n) {\n uploaded = new boolean[n+1];\n }\n \n public void upload(int video) {\n uploaded[video] = true;\n for(int i=lPrefix+1; i<uploaded.length; i++) {\n if(uploaded[i]) {\n ... | 1 | 0 | ['Java'] | 0 |
longest-uploaded-prefix | Very Very Easy| O(N) | very-very-easy-on-by-charitramehlawat-jeoa | \nclass LUPrefix {\npublic:\n vector<int>v;\n int count = 0;// will act as the index and the count of prefix\n LUPrefix(int n) {\n v.resize(n+5, | charitramehlawat | NORMAL | 2022-10-01T16:01:14.485735+00:00 | 2022-10-01T16:04:31.824639+00:00 | 143 | false | ```\nclass LUPrefix {\npublic:\n vector<int>v;\n int count = 0;// will act as the index and the count of prefix\n LUPrefix(int n) {\n v.resize(n+5,0);\n }\n \n void upload(int video) {\n // Set video-1->index as 1\n v[video-1] = 1;\n // take count as the index and increment... | 1 | 0 | ['C', 'C++'] | 0 |
longest-uploaded-prefix | Union Find - C++ | union-find-c-by-shivanshudobhal-u1sv | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | shivanshudobhal | NORMAL | 2025-04-10T16:21:52.074438+00:00 | 2025-04-10T16:21:52.074438+00:00 | 1 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# 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
`... | 0 | 0 | ['Union Find', 'C++'] | 0 |
longest-uploaded-prefix | easy solution | easy-solution-by-owenwu4-q86o | Intuitionobserve that starts at 1ApproachComplexity
Time complexity:
Space complexity:
Code | owenwu4 | NORMAL | 2025-04-04T21:16:52.925687+00:00 | 2025-04-04T21:16:52.925687+00:00 | 1 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
observe that starts at 1
# 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.... | 0 | 0 | ['Python3'] | 0 |
longest-uploaded-prefix | O(N) Approach | very easy in java | on-approach-very-easy-in-java-by-harikri-ove0 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | harikrishnakharikrishnak42 | NORMAL | 2025-03-09T16:36:54.759505+00:00 | 2025-03-09T16:36:54.759505+00:00 | 4 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# 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
`... | 0 | 0 | ['Java'] | 0 |
longest-uploaded-prefix | C++ solution with array | c-solution-with-array-by-oleksam-zwn8 | Please, upvote if you like it. Thanks :-)Complexity
Time complexity:
O(1)
Space complexity:
O(n)
Code | oleksam | NORMAL | 2025-03-07T20:49:04.474515+00:00 | 2025-03-07T20:49:04.474515+00:00 | 4 | false | Please, upvote if you like it. Thanks :-)
# Complexity
- Time complexity:
O(1)
- Space complexity:
O(n)
# Code
```cpp []
class LUPrefix {
public:
LUPrefix(int n) {
videos.resize(n + 1);
}
void upload(int video) {
videos[video] = 1;
while (maxUploaded + 1 < videos.size() && vi... | 0 | 0 | ['Array', 'Design', 'C++'] | 0 |
longest-uploaded-prefix | Python3 O(N) Solution with count sorting (99.05% Runtime) | python3-on-solution-with-count-sorting-9-drvg | IntuitionApproach
Define an array for count sorting and iteratively update corresnponding index.
Return the current index of the array and update it if needed. | missingdlls | NORMAL | 2025-02-21T06:55:50.507773+00:00 | 2025-02-21T06:55:50.507773+00:00 | 8 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->
- Define an array for count sorting and iteratively update... | 0 | 0 | ['Array', 'Math', 'Design', 'Queue', 'Counting', 'Monotonic Queue', 'Counting Sort', 'Python', 'Python3'] | 0 |
longest-uploaded-prefix | Python3 solution using list O(1) time, O(n) memory | python3-solution-using-list-o1-time-on-m-f9wu | IntuitionApproachComplexity
Time complexity:
O(1) for each of operations, O(n) if we include array initialization in constructor.
Space complexity:
O(n)
Cod | saitama1v1 | NORMAL | 2025-02-01T19:25:39.740407+00:00 | 2025-02-01T19:25:39.740407+00:00 | 12 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
O(1) for each of operations, O(n) if we include array initialization in constructor.
- Space complexity:
O(n)
# Code
```python3 []
class... | 0 | 0 | ['Python3'] | 0 |
longest-uploaded-prefix | Easy way to solve beat 100% | easy-way-to-solve-beat-100-by-anayet_has-8n5o | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Anayet_Hasan_Niloy | NORMAL | 2025-02-01T00:31:22.693676+00:00 | 2025-02-01T00:31:22.693676+00:00 | 4 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# 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
`... | 0 | 0 | ['C++'] | 0 |
longest-uploaded-prefix | 2424. Longest Uploaded Prefix | 2424-longest-uploaded-prefix-by-g8xd0qpq-xw6i | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | G8xd0QPqTy | NORMAL | 2025-01-18T14:46:36.229383+00:00 | 2025-01-18T14:46:36.229383+00:00 | 10 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# 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
`... | 0 | 0 | ['Python3'] | 0 |
longest-uploaded-prefix | Using DSU || Simple Beginner Friendly Solution with Dry Run | using-dsu-simple-beginner-friendly-solut-vpam | Intuitionprerequisite : DSU. If you don't know what this is then I'll recommend u to study that first. You can follow this to study dsu: DSU by StriverNow that | 5umit_kun | NORMAL | 2025-01-12T20:29:17.629749+00:00 | 2025-01-12T20:29:17.629749+00:00 | 9 | false | # Intuition
**prerequisite** : DSU. If you don't know what this is then I'll recommend u to study that first. You can follow this to study dsu: [DSU by Striver](https://takeuforward.org/data-structure/disjoint-set-union-by-rank-union-by-size-path-compression-g-46/)
Now that you know what dsu is lets understand why dsu... | 0 | 0 | ['Union Find', 'C++'] | 0 |
longest-uploaded-prefix | Beats 99% - simple boolean array O(1) Amortized | beats-99-simple-boolean-array-o1-amortiz-8lja | IntuitionCreate a boolean array of size n.
Keep track of where the longest prefix should be (initially 0);
Decrement each video for easier indexing.
If we uploa | aginton3 | NORMAL | 2025-01-08T21:25:41.032006+00:00 | 2025-01-08T21:25:41.032006+00:00 | 5 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Create a boolean array of size `n`.
Keep track of where the longest prefix should be (initially 0);
Decrement each video for easier indexing.
If we upload a video to longest position, then we know we have a block of at least length longest... | 0 | 0 | ['Java'] | 0 |
longest-uploaded-prefix | Lazy Calc Longest, constant upload, using array | lazy-calc-longest-constant-upload-using-5x56z | Intuitionwhen the longest is requested, start from the previously calculated longest and step forward and capture any additional uploads to prefix.ApproachMost | sajackson | NORMAL | 2025-01-03T21:40:40.462717+00:00 | 2025-01-03T21:40:40.462717+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
when the longest is requested, start from the previously calculated longest and step forward and capture any additional uploads to prefix.
# Approach
Most other solutions do the longest calculation at the end of upload(), this keeps the ca... | 0 | 0 | ['TypeScript'] | 0 |
longest-uploaded-prefix | Python (Simple BIT) | python-simple-bit-by-rnotappl-oybu | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | rnotappl | NORMAL | 2025-01-01T07:50:45.546448+00:00 | 2025-01-01T07:50:45.546448+00:00 | 10 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# 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
`... | 0 | 0 | ['Python3'] | 0 |
longest-uploaded-prefix | bitset fun | bitset-fun-by-aneeshsaripalli-cqll | Intuition\nWe need one-bit per index.\n\nWe\'ll have some left-padded block of bits. An upload may extend this block, or add a bit somewhere else in our storage | aneeshsaripalli | NORMAL | 2024-11-30T22:11:54.424271+00:00 | 2024-11-30T22:11:54.424302+00:00 | 2 | false | # Intuition\nWe need one-bit per index.\n\nWe\'ll have some left-padded block of bits. An upload may extend this block, or add a bit somewhere else in our storage.\n\nWe can just move our count pointer left to right when longest() is called This looks at every element which is O(N), so O(1) amortized cost.\n\nWe can us... | 0 | 0 | ['C++'] | 0 |
longest-uploaded-prefix | faster than 95%, CPP, O(n) worst case | faster-than-95-cpp-on-worst-case-by-lyjw-nqms | 1.\tvector<bool> done:\n \u2022\tThis vector is used to keep track of which videos have been uploaded. The index of the vector corresponds to the video I | LYjwjScNHF | NORMAL | 2024-11-24T18:51:49.642535+00:00 | 2024-11-24T18:51:49.642610+00:00 | 2 | false | 1.\t`vector<bool> done`:\n \u2022\tThis vector is used to keep track of which videos have been uploaded. The index of the vector corresponds to the video ID, and the value at that index indicates whether the video has been uploaded (`true`) or not (`false`).\n\t2.\t`int longestTillNow`:\n\t\u2022\tThis variable ... | 0 | 0 | ['C++'] | 0 |
longest-uploaded-prefix | SImple solution without binary search | simple-solution-without-binary-search-by-mhqz | \njava []\nclass LUPrefix {\n int max;\n int[]l;\n TreeSet<Integer>ts;\n // boolean \n public LUPrefix(int n) {\n max=0;\n l | risabhuchiha | NORMAL | 2024-11-23T23:11:46.514392+00:00 | 2024-11-23T23:11:46.514432+00:00 | 0 | false | \n```java []\nclass LUPrefix {\n int max;\n int[]l;\n TreeSet<Integer>ts;\n // boolean \n public LUPrefix(int n) {\n max=0;\n l=new int[n+2];\n ts=new TreeSet<>((a,b)->b-a);\n }\n \n public void upload(int v) {\n int ll=l[v-1];\n int rl=l[v+1];\n ... | 0 | 0 | ['Java'] | 0 |
number-of-orders-in-the-backlog | [Java/C++/Python] Priority Queue | javacpython-priority-queue-by-lee215-kn4u | Complexity\nTime O(nlogn)\nSpace O(n)\n\n\nJava\njava\n public int getNumberOfBacklogOrders(int[][] orders) {\n PriorityQueue<int[]> buy = new Priorit | lee215 | NORMAL | 2021-03-21T06:55:16.501446+00:00 | 2021-03-21T06:55:16.501475+00:00 | 9,673 | false | # **Complexity**\nTime `O(nlogn)`\nSpace `O(n)`\n<br>\n\n**Java**\n```java\n public int getNumberOfBacklogOrders(int[][] orders) {\n PriorityQueue<int[]> buy = new PriorityQueue<>((a, b) -> (b[0] - a[0]));\n PriorityQueue<int[]> sell = new PriorityQueue<>((a, b) -> (a[0] - b[0]));\n for (int[] o... | 131 | 5 | [] | 28 |
number-of-orders-in-the-backlog | Java/Python Heap Solution | javapython-heap-solution-by-admin007-ewv8 | If you got WA, you might need to see the following requirements:\nIf the order is a buy order, you look at the sell order with the smallest price in the backlog | admin007 | NORMAL | 2021-03-21T04:01:16.350877+00:00 | 2021-03-21T04:14:46.937593+00:00 | 3,559 | false | If you got WA, you might need to see the following requirements:\n**If the order is a buy order, you look at the sell order with the smallest price in the backlog.**\n**if the order is a sell order, you look at the buy order with the largest price in the backlog**\n\n**Please upvote for this if you find it is helpful!*... | 29 | 0 | [] | 3 |
number-of-orders-in-the-backlog | C++ 2 Heaps | c-2-heaps-by-votrubac-yp4e | A practical problem on how to process level 2 quotes. It took me a while to implement during the contest.\n\nWe can use min (for sell) and max (for buy) heaps. | votrubac | NORMAL | 2021-03-22T17:05:30.871238+00:00 | 2021-03-26T19:40:08.959661+00:00 | 1,736 | false | A practical problem on how to process [level 2 quotes](https://stockstotrade.com/understanding-level-2-quotes-infographic/). It took me a while to implement during the contest.\n\nWe can use min (for sell) and max (for buy) heaps. Note that we do not process an order right away, but just put it into one of the heaps. ... | 18 | 0 | [] | 4 |
number-of-orders-in-the-backlog | C++ solution | priority queues | easy to implement| Beats 100% | c-solution-priority-queues-easy-to-imple-mxbk | we initialise two priority queues, one of buy and other sell, after that we iterate through the orders, \nfor every order , we have two choices:\n-> ordertype i | srinivasteja18 | NORMAL | 2021-03-21T04:07:39.010106+00:00 | 2021-03-22T05:39:10.509606+00:00 | 1,356 | false | we initialise two priority queues, one of buy and other sell, after that we iterate through the orders, \nfor every order , we have two choices:\n-> ordertype is `0-buy`, here we check three cases,\n* \t\tif sell.size() ==0, we just push our current order into buy\n* \t\tif sell.top()[0] > p , that means smallest price... | 14 | 2 | [] | 2 |
number-of-orders-in-the-backlog | Python 3 || 9 lines, w/ explanation | python-3-9-lines-w-explanation-by-spauld-sll0 | 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 | Spaulding_ | NORMAL | 2023-01-03T21:07:24.565235+00:00 | 2024-06-10T20:26:20.242880+00:00 | 1,980 | false | 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 po... | 13 | 0 | ['Python3'] | 1 |
number-of-orders-in-the-backlog | Heap/PQ solution with logic [Python] | heappq-solution-with-logic-python-by-_ny-99ou | Logic is:\n Since we need to do a lot of find min/max operations: use 2 heaps:\n\t max-heap b for buy, min-heap s for sell\n\t So, max buy offer is on top of he | _nyctophiliac_ | NORMAL | 2021-03-21T04:05:37.900132+00:00 | 2021-03-21T05:55:24.565258+00:00 | 1,346 | false | Logic is:\n* Since we need to do a lot of **find min/max** operations: use 2 heaps:\n\t* max-heap `b` for buy, min-heap `s` for sell\n\t* So, max buy offer is on top of heap `b`\n\t* Min sell offer is on top of heap `s`\n* Each element of heap is an array: `[price, amount]`\n* *For* each buy/sell order:\n\t* Check for ... | 10 | 0 | ['Heap (Priority Queue)', 'Python', 'Python3'] | 2 |
number-of-orders-in-the-backlog | [Python3] priority queue | python3-priority-queue-by-ye15-sqcf | \n\nclass Solution:\n def getNumberOfBacklogOrders(self, orders: List[List[int]]) -> int:\n ans = 0\n buy, sell = [], [] # max-heap & min-heap | ye15 | NORMAL | 2021-03-21T04:03:58.847538+00:00 | 2021-03-22T00:02:37.904534+00:00 | 1,278 | false | \n```\nclass Solution:\n def getNumberOfBacklogOrders(self, orders: List[List[int]]) -> int:\n ans = 0\n buy, sell = [], [] # max-heap & min-heap \n \n for p, q, t in orders: \n ans += q\n if t: # sell order\n while q and buy and -buy[0][0] >= p: # mat... | 8 | 1 | ['Python3'] | 3 |
number-of-orders-in-the-backlog | Java Simple and easy solution, using Priority Queue, T O(n Log(n)), S O(n) clean code with comments | java-simple-and-easy-solution-using-prio-3tjd | PLEASE UPVOTE IF YOU LIKE THIS SOLUTION\n\n\n\n\nclass Solution {\n \n PriorityQueue<Order> buyBackLog;\n PriorityQueue<Order> sellBackLog;\n \n | satyaDcoder | NORMAL | 2021-03-30T13:20:47.454235+00:00 | 2021-03-30T13:20:47.454265+00:00 | 822 | false | **PLEASE UPVOTE IF YOU LIKE THIS SOLUTION**\n\n\n\n```\nclass Solution {\n \n PriorityQueue<Order> buyBackLog;\n PriorityQueue<Order> sellBackLog;\n \n static int MOD = 1_000_000_007;\n \n \n public int getNumberOfBacklogOrders(int[][] orders) {\n \n //max heap, heapify on price\n ... | 5 | 1 | ['Heap (Priority Queue)', 'Java'] | 1 |
number-of-orders-in-the-backlog | [Python] Concise Heap Implementation | python-concise-heap-implementation-by-za-klzt | Introduction\n\nWe need to find the total amount of orders that remain un-executed in the backlog of orders after a series of buy and sell orders have passed. A | zayne-siew | NORMAL | 2022-04-23T16:08:51.670524+00:00 | 2022-04-28T04:32:05.255954+00:00 | 806 | false | ### Introduction\n\nWe need to find the total amount of orders that remain un-executed in the backlog of orders after a series of buy and sell orders have passed. A buy order is executed if there exists a sell order in the backlog that has a selling price lower than or equal to the buying price, and a sell order is exe... | 4 | 0 | ['Heap (Priority Queue)', 'Python', 'Python3'] | 1 |
number-of-orders-in-the-backlog | Java TreeMap | java-treemap-by-mayank12559-uydh | \npublic int getNumberOfBacklogOrders(int[][] orders) {\n TreeMap<Integer, Long> buy = new TreeMap();\n TreeMap<Integer, Long> sell = new TreeMap( | mayank12559 | NORMAL | 2021-03-21T04:00:39.673759+00:00 | 2021-03-21T04:00:39.673791+00:00 | 461 | false | ```\npublic int getNumberOfBacklogOrders(int[][] orders) {\n TreeMap<Integer, Long> buy = new TreeMap();\n TreeMap<Integer, Long> sell = new TreeMap();\n for(int []order: orders){\n long orderCount = order[1];\n if(order[2] == 0){\n while(true){\n ... | 4 | 1 | [] | 3 |
number-of-orders-in-the-backlog | Java || 2 Priority Queues || 1ms Beats 90% | java-2-priority-queues-1ms-beats-90-by-d-7dgj | \nclass Order implements Comparable<Order> {\n int price, amount, orderType;\n Order(int price, int amount, int orderType) {\n this.price = price;\ | devansh2805 | NORMAL | 2022-04-14T08:16:11.302601+00:00 | 2022-04-14T08:16:11.302629+00:00 | 706 | false | ```\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... | 3 | 0 | ['Heap (Priority Queue)', 'Java'] | 0 |
number-of-orders-in-the-backlog | [C++] 2 Heaps | c-2-heaps-by-aparna_g-m61n | \nclass Solution {\npublic:\n int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n int n = orders.size();\n //0 - buy , 1 - sell; \n | aparna_g | NORMAL | 2021-07-18T18:49:08.605822+00:00 | 2021-07-18T18:49:25.443370+00:00 | 387 | false | ```\nclass Solution {\npublic:\n int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n int n = orders.size();\n //0 - buy , 1 - sell; \n priority_queue<vector<int>> buyBacklog;\n priority_queue<vector<int> , vector<vector<int>> , greater<vector<int>>> sellBacklog;\n \n ... | 3 | 0 | ['C', 'Heap (Priority Queue)', 'C++'] | 0 |
number-of-orders-in-the-backlog | Python // 2 Heaps // Readable code with dataclass | python-2-heaps-readable-code-with-datacl-gtwu | The readability of your code is as important as the correctness of your solution.\n\nWhenever possible, I like to convert input arrays into custom objects with | GroovySpoon | NORMAL | 2021-05-22T19:57:45.295861+00:00 | 2021-05-22T19:57:45.295918+00:00 | 607 | false | The readability of your code is as important as the correctness of your solution.\n\nWhenever possible, I like to convert input arrays into custom objects with readable field names.\n\n```Python\nfrom enum import IntEnum\nfrom dataclasses import dataclass, field\n\nclass oType(IntEnum):\n BUY = 0\n SELL = 1\n\n# ... | 3 | 0 | [] | 1 |
number-of-orders-in-the-backlog | C++ | priority Queue | solution | c-priority-queue-solution-by-quantico_ku-debk | \nclass Solution {\npublic:\n int mod = 1e9+7;\n int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n priority_queue<pair<int, int>>buy;\n | quantico_kush | NORMAL | 2021-03-21T11:51:40.273407+00:00 | 2021-03-21T11:59:31.080414+00:00 | 228 | false | ```\nclass Solution {\npublic:\n int mod = 1e9+7;\n int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n priority_queue<pair<int, int>>buy;\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> sell;\n for(auto x : orders)\n {\n int cnt =... | 3 | 0 | ['Heap (Priority Queue)'] | 0 |
number-of-orders-in-the-backlog | Python - Priority Queue Solution - O(nlogn) | python-priority-queue-solution-onlogn-by-myr3 | Maintain two priority queues. One for the buy orders and the other for the sell orders\n\nfrom queue import PriorityQueue\nclass Solution:\n def getNumberOfB | incomingoogle | NORMAL | 2021-03-21T07:36:11.165924+00:00 | 2021-03-21T07:52:22.219947+00:00 | 161 | false | Maintain two priority queues. One for the buy orders and the other for the sell orders\n```\nfrom queue import PriorityQueue\nclass Solution:\n def getNumberOfBacklogOrders(self, orders: List[List[int]]) -> int:\n buy_q = PriorityQueue()\n sell_q = PriorityQueue()\n\n for odr in orders:\n ... | 3 | 1 | [] | 0 |
number-of-orders-in-the-backlog | C++ | Map Solution | Question Explained | c-map-solution-question-explained-by-bla-odvp | The description of the question is quite difficult to understand. I\'ll put it in an easier way:\n\n1. when you buy (stock), you buy from the lowest sell orders | blackhole99 | NORMAL | 2021-03-21T05:08:20.515917+00:00 | 2021-03-24T16:28:47.668500+00:00 | 141 | false | The description of the question is quite difficult to understand. I\'ll put it in an easier way:\n\n1. when you buy (stock), you buy from the lowest sell orders up to your limit price, until everything available is exhausted;\n2. when you sell (stock), you sell to the highest buy orders to until your own limit price, u... | 3 | 2 | ['Tree', 'C'] | 0 |
number-of-orders-in-the-backlog | [Python] Heapq | python-heapq-by-qubenhao-arf0 | Buy list order by negative price so that it can be from greater to smaller.\n\npython\n def getNumberOfBacklogOrders(self, orders):\n """\n :ty | qubenhao | NORMAL | 2021-03-21T04:07:00.788957+00:00 | 2021-03-21T04:08:02.797754+00:00 | 381 | false | Buy list order by negative price so that it can be from greater to smaller.\n\n```python\n def getNumberOfBacklogOrders(self, orders):\n """\n :type orders: List[List[int]]\n :rtype: int\n """\n import heapq\n sells = []\n buys = []\n for p,a,t in orders:\n ... | 3 | 0 | ['Python'] | 0 |
number-of-orders-in-the-backlog | c++ | easy | fast | c-easy-fast-by-venomhighs7-hy0t | \n\n# Code\n\nclass Solution {\npublic:\n int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n priority_queue<vector<int>>buy;\n pr | venomhighs7 | NORMAL | 2022-11-21T05:34:20.116523+00:00 | 2022-11-21T05:34:20.116563+00:00 | 805 | false | \n\n# Code\n```\nclass Solution {\npublic:\n int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n priority_queue<vector<int>>buy;\n priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>>sell;\n for (auto& o : orders) {\n if (o[2] == 0)\n buy.... | 2 | 0 | ['C++'] | 0 |
number-of-orders-in-the-backlog | C++ two priority queue (EASY😈) | c-two-priority-queue-easy-by-rajwardhan2-0uql | \nclass Solution {\npublic:\n int mod=1e9+7;\n int getNumberOfBacklogOrders(vector<vector<int>>& nums) {\n priority_queue<pair<int,long long int>>b | Rajwardhan22 | NORMAL | 2022-08-02T09:58:46.791058+00:00 | 2022-08-02T09:58:46.791097+00:00 | 367 | false | ```\nclass Solution {\npublic:\n int mod=1e9+7;\n int getNumberOfBacklogOrders(vector<vector<int>>& nums) {\n priority_queue<pair<int,long long int>>buy;\n priority_queue<pair<int,long long int>,vector<pair<int,long long int>>,greater<pair<int,long long int>>>sell;\n int maxi1=0,maxi2=0;\n ... | 2 | 0 | ['C', 'Heap (Priority Queue)', 'C++'] | 0 |
number-of-orders-in-the-backlog | Modular | Good for interviews | Simulating stock market matching engine with Min and Max Heaps | modular-good-for-interviews-simulating-s-7dvr | \nfrom heapq import heappush, heappop\n\nclass MatchingEngine(object):\n \n def __init__(self):\n self.buy_orders = [] # Max heap\n self.se | jbond_007 | NORMAL | 2021-12-06T04:37:05.350410+00:00 | 2021-12-06T04:37:05.350451+00:00 | 1,818 | false | ```\nfrom heapq import heappush, heappop\n\nclass MatchingEngine(object):\n \n def __init__(self):\n self.buy_orders = [] # Max heap\n self.sell_orders = [] # Min heap \n \n def buy(self, buy_price, quantity):\n while len(self.sell_orders) > 0 and buy_price >= self.sell_orders[0][0] an... | 2 | 0 | ['Heap (Priority Queue)'] | 0 |
number-of-orders-in-the-backlog | (C++) 1801. Number of Orders in the Backlog | c-1801-number-of-orders-in-the-backlog-b-wer5 | \n\nclass Solution {\npublic:\n int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n priority_queue<pair<int, int>> buy; // max-heap \n | qeetcode | NORMAL | 2021-06-08T20:09:34.205672+00:00 | 2021-06-08T20:09:34.205703+00:00 | 285 | false | \n```\nclass Solution {\npublic:\n int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n priority_queue<pair<int, int>> buy; // max-heap \n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> sell; // min-heap \n \n for (auto& order : orders) {\n auto pric... | 2 | 0 | ['C'] | 0 |
number-of-orders-in-the-backlog | Python [max/min heap] | python-maxmin-heap-by-gsan-tdci | Buy orders are ranked from largest to smallest in price.\nSell orders are ranked from smallest to largest in price.\nWe add the orders in the order they arrive, | gsan | NORMAL | 2021-03-21T06:04:46.967197+00:00 | 2021-03-21T06:04:46.967229+00:00 | 135 | false | Buy orders are ranked from largest to smallest in price.\nSell orders are ranked from smallest to largest in price.\nWe add the orders in the order they arrive,\nwhen there is a match in prices we do the transaction.\n\n```python\nclass Solution:\n def getNumberOfBacklogOrders(self, orders):\n maxhp = []\n ... | 2 | 0 | [] | 0 |
number-of-orders-in-the-backlog | [C++] Solution with Two Priority_queues | c-solution-with-two-priority_queues-by-d-1hah | Idea:\nThis problem is like a trading system. With a bunch of sell orders, when a buying order comes in, the system would match the buying order with the sellin | davidchai | NORMAL | 2021-03-21T04:55:10.460337+00:00 | 2021-03-21T04:55:10.460362+00:00 | 1,491 | false | Idea:\nThis problem is like a trading system. With a bunch of sell orders, when a buying order comes in, the system would match the buying order with the selling orders whose prices is less than or equal to the buying prices. Same thing goes with the buy orders. In order to find which one is the best match, or there is... | 2 | 0 | ['C', 'Heap (Priority Queue)'] | 4 |
number-of-orders-in-the-backlog | Ruby - Keep sorted queues for buy and sell orders. | ruby-keep-sorted-queues-for-buy-and-sell-sdil | Keep buy queue sorted by price descending.\nKeep sell queue sorted by price ascending.\nBuy by the best price (minimum price - first in the sell queue) while ca | shhavel | NORMAL | 2021-03-21T04:54:38.171541+00:00 | 2021-03-21T06:50:11.392853+00:00 | 104 | false | Keep buy queue sorted by price descending.\nKeep sell queue sorted by price ascending.\nBuy by the best price (minimum price - first in the sell queue) while can.\nSell by the best price (maximum price - first in the buy queue) while can.\n\n```ruby\ndef get_number_of_backlog_orders(orders)\n bq = []; sq = [] # buy qu... | 2 | 0 | ['Binary Tree', 'Ruby'] | 1 |
number-of-orders-in-the-backlog | C++ beats 100% | c-beats-100-by-subbuffer-kp7t | Used two maps for each of the buys and sells; and using the iterator pointers, I would decrement the necessary map values.\n\nclass Solution {\npublic:\n int | SubBuffer | NORMAL | 2021-03-21T04:04:23.971530+00:00 | 2021-03-21T04:10:26.443268+00:00 | 323 | false | Used two maps for each of the buys and sells; and using the iterator pointers, I would decrement the necessary map values.\n```\nclass Solution {\npublic:\n int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n map<int,long> mpBuy;\n map<int,long> mpSell;\n int count = 0;\n for (i... | 2 | 0 | [] | 1 |
number-of-orders-in-the-backlog | [Python3] Clean and Clear - Two heaps | python3-clean-and-clear-two-heaps-by-_br-1y6q | \nclass Solution:\n def getNumberOfBacklogOrders(self, orders: List[List[int]]) -> int:\n buy, sell, MOD = [], [], 10**9 + 7\n \n def pr | _brian | NORMAL | 2021-03-21T04:03:05.238388+00:00 | 2021-03-21T04:03:05.238421+00:00 | 272 | false | ```\nclass Solution:\n def getNumberOfBacklogOrders(self, orders: List[List[int]]) -> int:\n buy, sell, MOD = [], [], 10**9 + 7\n \n def process_buy(buy_price, buy_amount):\n while buy_amount > 0:\n if not sell:\n break\n sell_price, se... | 2 | 0 | [] | 1 |
number-of-orders-in-the-backlog | [Java] Easy 2 Heap solution | java-easy-2-heap-solution-by-ytchouar-tge8 | java\nclass Solution {\n public int getNumberOfBacklogOrders(final int[][] orders) {\n final Queue<int[]> buy = new PriorityQueue<>((a, b) -> b[0] - a | YTchouar | NORMAL | 2024-06-14T04:01:44.541378+00:00 | 2024-06-14T04:01:44.541460+00:00 | 326 | false | ```java\nclass Solution {\n public int getNumberOfBacklogOrders(final int[][] orders) {\n final Queue<int[]> buy = new PriorityQueue<>((a, b) -> b[0] - a[0]);\n final Queue<int[]> sell = new PriorityQueue<>((a, b) -> a[0] - b[0]);\n\n for(final int[] order : orders) {\n if(order[2] ==... | 1 | 0 | ['Java'] | 0 |
number-of-orders-in-the-backlog | JS || Solution by Bharadwaj | js-solution-by-bharadwaj-by-manu-bharadw-hd8j | Code\n\nvar getNumberOfBacklogOrders = function (orders) {\n var bq = new MaxPriorityQueue({ priority: (bid) => bid[0] });\n var sq = new MinPriorityQueue | Manu-Bharadwaj-BN | NORMAL | 2024-03-01T06:33:40.846400+00:00 | 2024-03-01T06:33:40.846427+00:00 | 69 | false | # 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 ... | 1 | 0 | ['JavaScript'] | 1 |
number-of-orders-in-the-backlog | [C] Heap | c-heap-by-leetcodebug-tvzo | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | leetcodebug | NORMAL | 2023-11-30T04:47:04.338256+00:00 | 2023-11-30T04:47:04.338288+00:00 | 9 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(nlogn)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity ... | 1 | 0 | ['Array', 'C', 'Heap (Priority Queue)'] | 0 |
number-of-orders-in-the-backlog | Heap | cpp | heap-cpp-by-tan_b-v39p | \nclass Solution\n{\n public:\n struct cmp\n {\n bool operator()(pair<int, int> a, pair<int, int> b)\n {\n | Tan_B | NORMAL | 2023-01-02T14:46:58.676072+00:00 | 2023-01-02T14:46:58.676103+00:00 | 173 | false | ```\nclass Solution\n{\n public:\n struct cmp\n {\n bool operator()(pair<int, int> a, pair<int, int> b)\n {\n return a.first > b.first;\n }\n };\n void fun(priority_queue<pair<int, int>, vector< pair<int, int>>, cmp> &sell, priority_queue< pair<... | 1 | 0 | ['C++'] | 0 |
number-of-orders-in-the-backlog | Java Sol: Number of Orders in the Backlog | java-sol-number-of-orders-in-the-backlog-ahm7 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nminHeap for sell.\nmaxHeap for buy.\n Describe your approach to solving t | gyanendras1898 | NORMAL | 2023-01-01T08:50:11.036889+00:00 | 2023-01-01T08:50:11.036919+00:00 | 304 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nminHeap for sell.\nmaxHeap for buy.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n- O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n- O(n)\n... | 1 | 0 | ['Java'] | 0 |
number-of-orders-in-the-backlog | [GO] Use two heaps | go-use-two-heaps-by-zhouhaibing089-7jr5 | Intuition\n\nThis is a typical use case to find maximum and minimum elements with heap. The buy orders are the ones which we would like to find its highest pric | zhouhaibing089 | NORMAL | 2022-12-04T08:47:31.633517+00:00 | 2022-12-04T08:47:31.633559+00:00 | 68 | false | # Intuition\n\nThis is a typical use case to find maximum and minimum elements with heap. The buy orders are the ones which we would like to find its highest price at any point of time, and thus is a maximum heap, and similarly, the sell orders are the ones which we would like to find its lowest price at any point of t... | 1 | 0 | ['Go'] | 1 |
number-of-orders-in-the-backlog | Multiset Solution | Clean Code | Easy to Understand | multiset-solution-clean-code-easy-to-und-nhbm | Idea?\n Track the pairs {price,amount} for sell orders and buy orders seperately in a multiset.\n Whenever we have a buy order, keep popping out the selling ord | sunny_38 | NORMAL | 2022-04-03T08:00:20.059111+00:00 | 2022-04-03T08:01:11.051063+00:00 | 138 | false | **Idea?**\n* Track the pairs **{price,amount**} for sell orders and buy orders seperately in a **multiset**.\n* Whenever we have a *buy orde*r, **keep popping out the selling orders** present in the backlog that are less than or equal to current price and number of orders left is still positive.\n* Also, Whenever we ha... | 1 | 0 | ['C'] | 0 |
number-of-orders-in-the-backlog | Python solution using minheap and maxheap | python-solution-using-minheap-and-maxhea-l7fp | \nclass Solution:\n def getNumberOfBacklogOrders(self, orders: List[List[int]]) -> int:\n \'\'\'\n 2D array orders \n orders[i] = [price | ikna | NORMAL | 2021-11-06T04:11:07.974336+00:00 | 2021-11-06T04:11:07.974380+00:00 | 168 | false | ```\nclass Solution:\n def getNumberOfBacklogOrders(self, orders: List[List[int]]) -> int:\n \'\'\'\n 2D array orders \n orders[i] = [price, amount, orderType]\n 0 = buy\n 1 = sell\n \n backlog = []\n \n if order == buy:\n if any get the sell_... | 1 | 0 | ['Heap (Priority Queue)', 'Python'] | 0 |
number-of-orders-in-the-backlog | C++ priority Queue based solution || beginner friendly code | c-priority-queue-based-solution-beginner-zh5n | \nclass Solution {\npublic:\n int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n \n priority_queue<pair<int,int>,vector<pair<int,int | 007shaswatkumar | NORMAL | 2021-08-11T18:33:51.989179+00:00 | 2021-08-11T18:33:51.989219+00:00 | 271 | false | ```\nclass Solution {\npublic:\n int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n \n priority_queue<pair<int,int>,vector<pair<int,int>> > buy; //max queue for buy\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>> >sell;//min queue for sell\n \n ... | 1 | 0 | ['C', 'Heap (Priority Queue)', 'C++'] | 0 |
number-of-orders-in-the-backlog | c++(196ms 99%) two maps | c196ms-99-two-maps-by-zx007pi-ngk8 | Runtime: 196 ms, faster than 98.82% of C++ online submissions for Number of Orders in the Backlog.\nMemory Usage: 64.5 MB, less than 39.53% of C++ online submis | zx007pi | NORMAL | 2021-07-19T16:34:16.041777+00:00 | 2021-07-19T16:40:15.189254+00:00 | 149 | false | Runtime: 196 ms, faster than 98.82% of C++ online submissions for Number of Orders in the Backlog.\nMemory Usage: 64.5 MB, less than 39.53% of C++ online submissions for Number of Orders in the Backlog.\n```\nclass Solution {\npublic:\n int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n map<int, long> bu... | 1 | 0 | ['C', 'C++'] | 0 |
number-of-orders-in-the-backlog | Python easy to understand with comments (heaps) | python-easy-to-understand-with-comments-rgi25 | 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_ | riyasat | NORMAL | 2021-03-24T19:41:43.450284+00:00 | 2021-03-24T19:41:43.450326+00:00 | 180 | false | 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... | 1 | 1 | ['Heap (Priority Queue)', 'Python'] | 0 |
number-of-orders-in-the-backlog | Java | Priority Queue | java-priority-queue-by-bhattfrequent-b4p5 | \nclass Solution {\n public int getNumberOfBacklogOrders(int[][] orders) {\n PriorityQueue<BO> pqBo = new PriorityQueue(new BOComp());\n Priori | bhattfrequent | NORMAL | 2021-03-23T03:14:35.236267+00:00 | 2021-03-23T03:14:35.236304+00:00 | 134 | false | ```\nclass Solution {\n public int getNumberOfBacklogOrders(int[][] orders) {\n PriorityQueue<BO> pqBo = new PriorityQueue(new BOComp());\n PriorityQueue<SO> pqSo = new PriorityQueue(new SOComp());\n // IF BUY CHECK SMALLEST SELL, SELL SHOULD BE LESS\n // IF SELL CHECK LARGEST BUY, BUY SH... | 1 | 0 | [] | 1 |
number-of-orders-in-the-backlog | C# SortedSet - O(N*LogN) time | c-sortedset-onlogn-time-by-xenfruit-b4f3 | SortedSet works as a priority queue here. SortedSet.Min, SortedSet.Max, SortedSet.Add and SortedSet.Remove methods take LogN time each which leads to O(NLogN) t | xenfruit | NORMAL | 2021-03-22T04:18:24.421930+00:00 | 2021-03-29T15:13:11.142541+00:00 | 107 | false | SortedSet works as a priority queue here. SortedSet.Min, SortedSet.Max, SortedSet.Add and SortedSet.Remove methods take LogN time each which leads to O(NLogN) time complexity overall.\nWe need method AddOrder because SortedSet doesn\'t allow to store duplicates.\n```\npublic class Solution\n{\n public int GetNumberO... | 1 | 0 | [] | 0 |
number-of-orders-in-the-backlog | Java Solution with Priority Queue | java-solution-with-priority-queue-by-raj-i25q | \nclass Solution {\n static int mod = 1000000007;\n \n public int getNumberOfBacklogOrders(int[][] orders) {\n Queue<int[]> buyBacklog = new Pri | rajanpupa | NORMAL | 2021-03-21T22:18:15.802549+00:00 | 2021-03-21T22:18:15.802592+00:00 | 86 | false | ```\nclass Solution {\n static int mod = 1000000007;\n \n public int getNumberOfBacklogOrders(int[][] orders) {\n Queue<int[]> buyBacklog = new PriorityQueue<>((a,b) -> b[0]-a[0]);\n Queue<int[]> sellBacklog = new PriorityQueue<>((a,b) -> a[0]-b[0]);\n \n \n \n for(int... | 1 | 0 | [] | 0 |
number-of-orders-in-the-backlog | Java | Runtime and Memory 100% | java-runtime-and-memory-100-by-ryanrehma-7tj6 | \nclass Solution {\n int MOD = 1000000007;\n public void insert(int elem, ArrayList<Integer> backlog, int[][] orders) {\n int left = 0, right = bac | ryanrehman99 | NORMAL | 2021-03-21T09:15:47.785073+00:00 | 2021-03-21T09:15:47.785106+00:00 | 77 | false | ```\nclass Solution {\n int MOD = 1000000007;\n public void insert(int elem, ArrayList<Integer> backlog, int[][] orders) {\n int left = 0, right = backlog.size();\n while (left < right) {\n int mid = left + (right - left) / 2;\n if (orders[elem][0] > orders[backlog.get(mid)][0]... | 1 | 0 | [] | 0 |
number-of-orders-in-the-backlog | Java PriorityQueue. Simple and Straightforward | java-priorityqueue-simple-and-straightfo-twy3 | Idea is very simple. Maintain a min heap for sell backlogs and maxHeap for buy backlogs.\nWhen order is sell order we will tye to fullfill it from buy backlog w | Jenjoy | NORMAL | 2021-03-21T07:28:26.405356+00:00 | 2021-03-21T07:36:25.816639+00:00 | 91 | false | Idea is very simple. Maintain a min heap for sell backlogs and maxHeap for buy backlogs.\nWhen order is sell order we will tye to fullfill it from buy backlog with making sure conditions are met and vice versa.\n\nAt the end go through both the backlogs and compute total backlogs orders\n\nMore commets and explaination... | 1 | 0 | [] | 0 |
number-of-orders-in-the-backlog | The Example to Practice DRY | the-example-to-practice-dry-by-haoel-2edi | \n\nclass Order {\npublic:\n int price;\n int amount;\n};\n\nenum COMP { GREATER, LESS };\n\ntemplate <COMP op>\nclass OrderComp {\npublic:\n bool oper | haoel | NORMAL | 2021-03-21T07:12:41.995627+00:00 | 2021-03-21T07:12:41.995660+00:00 | 106 | false | \n```\nclass Order {\npublic:\n int price;\n int amount;\n};\n\nenum COMP { GREATER, LESS };\n\ntemplate <COMP op>\nclass OrderComp {\npublic:\n bool operator() (const Order& lhs, const Order& rhs) {\n if (op == GREATER) {\n return lhs.price > rhs.price;\n }\n return lhs.price <... | 1 | 0 | [] | 0 |
number-of-orders-in-the-backlog | [JavaScript] 2 Heap Solution w/ explanation | javascript-2-heap-solution-w-explanation-ua1r | javascript\nvar getNumberOfBacklogOrders = function(orders) {\n const buyHeap = new Heap((child, parent) => child.price > parent.price)\n const sellHeap = | stevenkinouye | NORMAL | 2021-03-21T07:05:41.505823+00:00 | 2021-03-21T07:07:05.858663+00:00 | 227 | false | ```javascript\nvar getNumberOfBacklogOrders = function(orders) {\n const buyHeap = new Heap((child, parent) => child.price > parent.price)\n const sellHeap = new Heap((child, parent) => child.price < parent.price)\n \n for (let [price, amount, orderType] of orders) {\n \n // sell\n if (... | 1 | 0 | ['Heap (Priority Queue)', 'JavaScript'] | 1 |
number-of-orders-in-the-backlog | Python 3, Heap and Dictionary | python-3-heap-and-dictionary-by-silvia42-d7wb | We use two heaps:\nlogBuy is storing MINUS prices, because we will need the highest price first.\nlogSell is storing prices, because we will need the lowest pri | silvia42 | NORMAL | 2021-03-21T05:15:18.291466+00:00 | 2021-03-21T13:25:09.069889+00:00 | 112 | false | We use two heaps:\n```logBuy``` is storing MINUS prices, because we will need the highest price first.\n```logSell``` is storing prices, because we will need the lowest price first.\n\nWe use two dictonaries:\n```dictBuy[k]``` is number of prices ```-k``` in ```Buy Backlog```\n```dictSell[k]``` is number of prices ```k... | 1 | 0 | ['Heap (Priority Queue)', 'Python'] | 0 |
number-of-orders-in-the-backlog | [Python3] Simple Solution with Priority Queue (100 % Time & Space Efficiency) | python3-simple-solution-with-priority-qu-2wml | \nclass Solution:\n def getNumberOfBacklogOrders(self, orders: List[List[int]]) -> int:\n buy, sell = [], []\n \n for order in orders:\n | leonardthong | NORMAL | 2021-03-21T04:25:18.242163+00:00 | 2021-03-21T04:26:07.477654+00:00 | 71 | false | ```\nclass Solution:\n def getNumberOfBacklogOrders(self, orders: List[List[int]]) -> int:\n buy, sell = [], []\n \n for order in orders:\n if order[2] == 0:\n while len(sell) > 0:\n if 0 >= len(sell) or 0 == order[1]: break\n\n se ... | 1 | 0 | [] | 0 |
number-of-orders-in-the-backlog | [Kotlin]Good problem. Let's implement the core datastruct of a matching engine. | kotlingood-problem-lets-implement-the-co-tu9n | It\'s really a good problem. It\'s the core datastruct of a matching engine. I really know it cause my job is about it.\n\nUsually we use the the LMAX Architect | azzssss | NORMAL | 2021-03-21T04:13:14.528484+00:00 | 2021-03-21T04:20:17.618719+00:00 | 431 | false | It\'s really a good problem. It\'s the core datastruct of a matching engine. I really know it cause my job is about it.\n\nUsually we use the the LMAX Architecture to implement a mathing engine. If you are interested in it, you can read this article [The LMAX Architecture](https://martinfowler.com/articles/lmax.html).\... | 1 | 1 | [] | 0 |
number-of-orders-in-the-backlog | C++ priority queue | c-priority-queue-by-navysealsniper-34lz | \n\n int getNumberOfBacklogOrders(vector>& orders) {\n std::priority_queue, vector\>> buy;\n auto cmp = {return a[0] > b[0];};\n std::p | navysealsniper | NORMAL | 2021-03-21T04:08:12.044211+00:00 | 2021-03-21T04:08:12.044253+00:00 | 68 | false | \n\n int getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n std::priority_queue<vector<int>, vector<vector<int>>> buy;\n auto cmp = [](vector<int>& a, vector<int>& b) {return a[0] > b[0];};\n std::priority_queue<vector<int>, vector<vector<int>>, decltype(cmp)> sell(cmp);\n int mod ... | 1 | 0 | [] | 0 |
number-of-orders-in-the-backlog | [TypeScript] Skew Heap | typescript-skew-heap-by-shinkashi-t0i3 | I like Skew Heap. It\'s much simpler than usual healps and easy to customise.\n\ntypescript\nconst MOD = 10 ** 9 + 7;\n\nclass Node {\n constructor(\n | shinkashi | NORMAL | 2021-03-21T04:04:36.714479+00:00 | 2021-03-21T04:04:36.714511+00:00 | 93 | false | I like Skew Heap. It\'s much simpler than usual healps and easy to customise.\n\n```typescript\nconst MOD = 10 ** 9 + 7;\n\nclass Node {\n constructor(\n public price: number,\n public amount: number,\n public left: Node | null = null,\n public right: Node | null = null\n ) { };\n}\n\n... | 1 | 0 | [] | 0 |
number-of-orders-in-the-backlog | [C++] Priority Queue Solution | c-priority-queue-solution-by-vector_long-awly | The problem description is really confusing.\n\nIntuition:\n\nDo what the description states.\n\nUsing a priority queue to store buy and sell respectively, sell | vector_long_long | NORMAL | 2021-03-21T04:01:48.986509+00:00 | 2021-03-21T04:02:28.708492+00:00 | 363 | false | The problem description is really confusing.\n\n**Intuition**:\n\nDo what the description states.\n\nUsing a priority queue to store buy and sell respectively, sell sorted from smallest to largest, buy sorted from largest to smallest.\n\nA very important insight is that do not store individual orders, instead, store th... | 1 | 0 | ['C', 'Heap (Priority Queue)', 'C++'] | 1 |
number-of-orders-in-the-backlog | Min and max Heap | min-and-max-heap-by-wei130-2rfy | \tclass Solution(object):\n\t\tdef getNumberOfBacklogOrders(self, orders):\n\t\t\t"""\n\t\t\t:type orders: List[List[int]]\n\t\t\t:rtype: int\n\t\t\t"""\n\t\t\t | wei130 | NORMAL | 2021-03-21T04:01:31.150154+00:00 | 2021-03-21T04:01:31.150187+00:00 | 205 | false | \tclass Solution(object):\n\t\tdef getNumberOfBacklogOrders(self, orders):\n\t\t\t"""\n\t\t\t:type orders: List[List[int]]\n\t\t\t:rtype: int\n\t\t\t"""\n\t\t\tbuy = []\n\t\t\tsell = []\n\t\t\tfor i in range(len(orders)):\n\t\t\t\torder = orders[i]\n\t\t\t\tif order[2] == 0:\n\t\t\t\t\twhile sell and sell[0][0] <= orde... | 1 | 0 | [] | 0 |
number-of-orders-in-the-backlog | Easy to understand 2 order queue solution for javascript | easy-to-understand-2-order-queue-solutio-t7pz | NotesSeems like all the JavasScript solution out there is using outdated syntax. We need to use an external library unlike python. This is an answer that'll act | alexanderyst | NORMAL | 2025-04-12T01:29:35.854850+00:00 | 2025-04-12T01:29:35.854850+00:00 | 1 | false | # Notes
Seems like all the JavasScript solution out there is using outdated syntax. We need to use an external library unlike python. This is an answer that'll actually pass.
# Approach
Maintain a max queue for buy orders (since we always want the highest price) and min queue for sell orders (since we always want the ... | 0 | 0 | ['JavaScript'] | 0 |
number-of-orders-in-the-backlog | priority queue | priority-queue-by-rajeshkumar1130-euq7 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | rajeshkumar1130 | NORMAL | 2025-04-03T05:55:16.289090+00:00 | 2025-04-03T05:55:16.289090+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# 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
`... | 0 | 0 | ['C#'] | 0 |
number-of-orders-in-the-backlog | two priority_queue | two-priority_queue-by-johnchen-umqk | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | johnchen | NORMAL | 2025-03-28T14:51:17.487658+00:00 | 2025-03-28T14:51:17.487658+00:00 | 5 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# 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
`... | 0 | 0 | ['C++'] | 0 |
number-of-orders-in-the-backlog | Wouldn't the time complexity be O(N^2 logN) using priority queues? | wouldnt-the-time-complexity-be-on2-logn-qws3q | IntuitionUsing two priority queues like most of the solutions posted here.ApproachComplexity
Time complexity:
Inside the for loop, there is a while loop that mi | xzw0005 | NORMAL | 2025-03-03T00:45:45.355174+00:00 | 2025-03-03T00:45:45.355174+00:00 | 7 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Using two priority queues like most of the solutions posted here.
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
Inside the for loop... | 0 | 0 | ['Python3'] | 0 |
number-of-orders-in-the-backlog | C++ easy solution using 2 priority queues | c-easy-solution-using-2-priority-queues-ta42x | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | hunny123 | NORMAL | 2025-02-12T20:03:27.668910+00:00 | 2025-02-12T20:03:27.668910+00:00 | 4 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# 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
`... | 0 | 0 | ['C++'] | 0 |
number-of-orders-in-the-backlog | количество заказов в бэклоге | kolichestvo-zakazov-v-bekloge-by-elliot0-nj8o | ИнтуицияПодходСложность
Временная сложность:
Сложность пространства:
Код | Elliot0-1 | NORMAL | 2025-02-08T15:17:02.238739+00:00 | 2025-02-08T15:17:02.238739+00:00 | 4 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# 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
`... | 0 | 0 | ['JavaScript'] | 0 |
number-of-orders-in-the-backlog | C# 100% best runtime 90% best memory using only two priority queues | c-100-best-runtime-90-best-memory-using-ypxla | ProofIntuition + ApproachWe need to keep track of low sell price because problem says we need to match buys with the smallest sell price.We need to keep track o | gabida | NORMAL | 2025-02-04T21:32:50.664188+00:00 | 2025-02-04T21:32:50.664188+00:00 | 7 | false | # Proof

# Intuition + Approach
We need to keep track of low sell price because problem says we need to match buys with the smallest sell price.
We need to keep track of high buy price to match it with ... | 0 | 0 | ['C#'] | 0 |
number-of-orders-in-the-backlog | Easy to understand Java solution - Using 2 Priority queues | easy-to-understand-java-solution-using-2-8jhi | 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 | pushkardg | NORMAL | 2025-01-13T00:26:27.981606+00:00 | 2025-01-13T00:26:27.981606+00:00 | 9 | false | # 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... | 0 | 0 | ['Java'] | 0 |
number-of-orders-in-the-backlog | Heap | Simulation | heap-simulation-by-anonymous_k-cdm1 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | anonymous_k | NORMAL | 2025-01-08T20:49:03.627829+00:00 | 2025-01-08T20:49:03.627829+00:00 | 9 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# 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
`... | 0 | 0 | ['Python3'] | 0 |
number-of-orders-in-the-backlog | build an order-book and match-orders | build-an-order-book-and-match-orders-by-zrbz3 | IntuitionFirst thought: I need a sorted data structure to provide me min and max on pricesApproachCould use binary-search-tree or priority-queue; opted for PQ, | asafbu | NORMAL | 2024-12-28T11:01:02.435233+00:00 | 2024-12-28T11:01:02.435233+00:00 | 15 | false | # Intuition
First thought: I need a sorted data structure to provide me min and max on prices
# Approach
Could use binary-search-tree or priority-queue; opted for PQ, because I really do not need to sort each node, just need the min for asks and max for bids.
# Complexity
- Time complexity:
O(nlogn)
- Space complexi... | 0 | 0 | ['Array', 'Sorting', 'Heap (Priority Queue)', 'Java'] | 0 |
number-of-orders-in-the-backlog | OOP Design Solution | oop-design-solution-by-deydev-77af | null | deydev | NORMAL | 2024-12-27T09:13:13.130731+00:00 | 2024-12-31T02:23:50.061103+00:00 | 12 | false |
```python []
BUY_ORDERS = 0
SELL_ORDERS = 1
MOD = int(1e9 + 7)
class OrderBook:
def __init__(self, order_type) -> None:
self.order_type = order_type
self.price_orders_map: dict[int, int] = {}
self.price_heap: list[int] = []
self.backlog = 0
def push(self, price, orders) -> Non... | 0 | 0 | ['Design', 'Heap (Priority Queue)', 'Simulation', 'C++', 'Python3'] | 0 |
number-of-orders-in-the-backlog | TypeScript Clean Min & Max Heaps Solution | typescript-clean-min-max-heaps-solution-n77yy | IntuitionKeep two heaps, max heap for buy, min heap for sell backlogs.ApproachJust simulate the process as explained in the question.Complexity
Time complexity | shtanriverdi | NORMAL | 2024-12-24T08:21:39.091156+00:00 | 2024-12-24T08:21:39.091156+00:00 | 10 | false | # Intuition
Keep two heaps, max heap for buy, min heap for sell backlogs.
# Approach
Just simulate the process as explained in the question.
# Complexity
- Time complexity:
O(N log N)
- Space complexity:
O(N)
# Code
```typescript []
function getNumberOfBacklogOrders(orders: number[][]): number {
const buyMaxHea... | 0 | 0 | ['Array', 'Heap (Priority Queue)', 'Simulation', 'TypeScript'] | 0 |
number-of-orders-in-the-backlog | C++ solutions Two Heaps | c-solutions-two-heaps-by-oleksam-tl48 | \n// Please, upvote if you like it. Thanks :-)\n// TC - O(nlog(n))\n// SC - O(n)\ntypedef pair<int, int> pii;\nint getNumberOfBacklogOrders(vector<vector<int>>& | oleksam | NORMAL | 2024-12-06T14:57:02.554166+00:00 | 2024-12-06T14:57:02.554208+00:00 | 3 | false | ```\n// Please, upvote if you like it. Thanks :-)\n// TC - O(nlog(n))\n// SC - O(n)\ntypedef pair<int, int> pii;\nint getNumberOfBacklogOrders(vector<vector<int>>& orders) {\n\tpriority_queue<pii> buy;\n\tpriority_queue<pii, vector<pii>, greater<pii>> sell;\n\tfor (const auto& order : orders) {\n\t\tint price = order[0... | 0 | 0 | ['Greedy', 'C', 'Heap (Priority Queue)', 'C++'] | 0 |
number-of-orders-in-the-backlog | Python3. Heap | python3-heap-by-srptv-vt4w | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | srptv | NORMAL | 2024-11-11T16:47:34.704970+00:00 | 2024-11-11T16:47:34.705010+00:00 | 5 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Python3'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.