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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
design-an-ordered-stream | bad problem description | bad-problem-description-by-thelotuseater-5rhs | What is the problem asking for, the description and the example are so conflicting. English is my first language, I have never had any issues with understanding | thelotuseater | NORMAL | 2022-08-05T01:59:14.979103+00:00 | 2022-08-05T02:00:43.070965+00:00 | 7,812 | false | What is the problem asking for, the description and the example are so conflicting. English is my first language, I have never had any issues with understanding problems on LC. I am a premium user, please fix this. | 161 | 0 | [] | 13 |
design-an-ordered-stream | Java Straightforward Solution! | java-straightforward-solution-by-admin00-r6ow | Well, the problem statement is not very clear even there is a GIF, although I work it out. The problem statement makes it feel as a medium problem, I guess. \n\ | admin007 | NORMAL | 2020-11-15T04:01:26.480013+00:00 | 2020-11-15T07:34:11.551157+00:00 | 14,740 | false | Well, the problem statement is not very clear even there is a GIF, although I work it out. The problem statement makes it feel as a medium problem, I guess. \n\nBasically, the idea is that you need to return a longest list that start at index of ptr. if ptr is not pointing an element, you need to return a empty list.\n... | 72 | 2 | ['Java'] | 8 |
design-an-ordered-stream | [Python3] simple solution | python3-simple-solution-by-ye15-2k67 | \n\nclass OrderedStream:\n\n def __init__(self, n: int):\n self.data = [None]*n\n self.ptr = 0 # 0-indexed \n\n def insert(self, id: int, va | ye15 | NORMAL | 2020-11-15T04:03:14.174746+00:00 | 2020-11-15T04:03:14.174782+00:00 | 14,274 | false | \n```\nclass OrderedStream:\n\n def __init__(self, n: int):\n self.data = [None]*n\n self.ptr = 0 # 0-indexed \n\n def insert(self, id: int, value: str) -> List[str]:\n id -= 1 # 0-indexed \n self.data[id] = value \n if id > self.ptr: return [] # not reaching ptr \n \n ... | 60 | 1 | ['Python3'] | 4 |
design-an-ordered-stream | Bloomberg Question with Variation | bloomberg-question-with-variation-by-vin-ij41 | I recently got this quesiton in a phone interview at Bloomberg with a minor variation. The variation was that you won\'t be given size in advance. So, try to so | vinodghai713 | NORMAL | 2022-10-05T21:06:49.567256+00:00 | 2022-10-05T21:06:49.567298+00:00 | 4,400 | false | I recently got this quesiton in a phone interview at Bloomberg with a minor variation. The variation was that you won\'t be given **size** in advance. So, try to solve this question without using variable **n** in the constructor. Here is my implementation.\n\n```\nclass OrderedStream {\n private Map<Integer, String... | 33 | 0 | ['Java'] | 5 |
design-an-ordered-stream | Latest Python solution explained for newly updated description: Faster than 90% | latest-python-solution-explained-for-new-vgrx | The idea behind this problem is simple but the description is confusing.\nSo let me explain a bit.\n\nBasically , we need to store every incoming value at the g | er1shivam | NORMAL | 2021-07-14T03:04:33.554067+00:00 | 2021-07-14T03:04:33.554113+00:00 | 4,502 | false | The idea behind this problem is simple but the description is confusing.\nSo let me explain a bit.\n\nBasically , we need to store every incoming value at the given index. And \nwith every incoming index, we have to check\n\n* If the current index is less than the incoming index, the we have to return\n an empty lis... | 33 | 0 | ['Python', 'Python3'] | 2 |
design-an-ordered-stream | [JavaScript] Elegant solution using an array and pointer (with explanation) | javascript-elegant-solution-using-an-arr-1yvf | This is a rather simple problem, all we need to do is to store all the data that was passed to insert() function, return some data if the condition is true, and | mrhyde | NORMAL | 2021-02-22T22:45:48.229029+00:00 | 2021-06-22T23:25:32.275889+00:00 | 2,556 | false | This is a rather simple problem, all we need to do is to store all the data that was passed to `insert()` function, return some data if the condition is true, and keep track of where we were last time.\n\nLook how clean this solution is:\n```javascript\nclass OrderedStream {\n constructor(n) {\n this.pointer = 0\n ... | 26 | 1 | ['JavaScript'] | 2 |
design-an-ordered-stream | C++ Array | c-array-by-votrubac-wb74 | cpp\nvector<string> s;\nint ptr = 1;\nOrderedStream(int n) : s(n + 1) {}\nvector<string> insert(int id, string value) {\n s[id] = value;\n vector<string> | votrubac | NORMAL | 2020-11-15T05:00:47.505906+00:00 | 2021-02-18T10:47:47.655621+00:00 | 4,567 | false | ```cpp\nvector<string> s;\nint ptr = 1;\nOrderedStream(int n) : s(n + 1) {}\nvector<string> insert(int id, string value) {\n s[id] = value;\n vector<string> res;\n while (ptr < s.size() && !s[ptr].empty())\n res.push_back(s[ptr++]);\n return res;\n}\n``` | 24 | 2 | [] | 3 |
design-an-ordered-stream | Python using dict, 212ms 14.6MB | python-using-dict-212ms-146mb-by-vashik-dom3 | \nclass OrderedStream:\n\n def __init__(self, n: int):\n self.seen = {}\n self.ptr = 1\n\n def insert(self, id: int, value: str) -> List[str | vashik | NORMAL | 2020-11-16T13:47:52.104013+00:00 | 2020-11-16T13:47:52.104045+00:00 | 2,146 | false | ```\nclass OrderedStream:\n\n def __init__(self, n: int):\n self.seen = {}\n self.ptr = 1\n\n def insert(self, id: int, value: str) -> List[str]:\n seen, ptr = self.seen, self.ptr\n \n seen[id] = value\n result = []\n while ptr in seen:\n result.append(s... | 17 | 0 | ['Python', 'Python3'] | 2 |
design-an-ordered-stream | C++ Self Explainatory | c-self-explainatory-by-0xsupra-g290 | \nclass OrderedStream {\npublic:\n \n vector<string>res;\n int ptr;\n OrderedStream(int n) {\n res.resize(n);\n ptr = 1;\n }\n \ | 0xsupra | NORMAL | 2020-11-15T04:01:36.290465+00:00 | 2020-11-15T04:01:36.290512+00:00 | 4,003 | false | ```\nclass OrderedStream {\npublic:\n \n vector<string>res;\n int ptr;\n OrderedStream(int n) {\n res.resize(n);\n ptr = 1;\n }\n \n vector<string> insert(int id, string value) {\n res[id-1] = value;\n vector<string> ans;\n \n if(ptr == id) {\n i... | 13 | 1 | ['C', 'C++'] | 0 |
design-an-ordered-stream | Python3 Solution + Better Description Because This One Is Really Bad | python3-solution-better-description-beca-lv4j | The description as of June 13th, 2022 mentions nothing a ptr. There is a ptr that should be initialized at 1. If an item is inserted with an idKey above the ptr | bretticus-mc | NORMAL | 2022-06-14T00:30:22.773100+00:00 | 2022-06-14T00:30:22.773127+00:00 | 1,345 | false | The description as of June 13th, 2022 mentions nothing a ptr. There is a ptr that should be initialized at 1. If an item is inserted with an idKey above the ptr, return nothing. If an item is inserted that matches the ptr, return the largest chunk of contiguous values above the ptr. The ptr should update to the index i... | 12 | 1 | ['Python3'] | 0 |
design-an-ordered-stream | C++ God Solution | c-god-solution-by-vishal_k78-fyhk | Map STL\n\nclass OrderedStream {\npublic:\n map<int,string> mp;\n int maxSize = -1,currIndex = 1;\n \n OrderedStream(int n) {\n maxSize = n;\ | vishal_k78 | NORMAL | 2022-10-30T09:43:40.608402+00:00 | 2022-10-30T09:43:40.608428+00:00 | 1,761 | false | **Map STL**\n```\nclass OrderedStream {\npublic:\n map<int,string> mp;\n int maxSize = -1,currIndex = 1;\n \n OrderedStream(int n) {\n maxSize = n;\n for(int i=1;i<=n;i++) mp[i] = "----";\n }\n \n vector<string> insert(int idKey, string value) {\n vector<string> res;\n m... | 10 | 1 | ['Array', 'C', 'C++'] | 2 |
design-an-ordered-stream | Java, faster than 100%. Understand the requirments is much harder than problem itself | java-faster-than-100-understand-the-requ-r94b | \nclass OrderedStream {\n \n private String[] values;\n private int ptr;\n\n public OrderedStream(int n) {\n values = new String[n];\n | yurokusa | NORMAL | 2020-11-16T21:22:37.916228+00:00 | 2020-11-16T21:23:29.827822+00:00 | 2,871 | false | ```\nclass OrderedStream {\n \n private String[] values;\n private int ptr;\n\n public OrderedStream(int n) {\n values = new String[n];\n ptr = 0;\n }\n \n public List<String> insert(int id, String value) {\n values[id - 1] = value;\n\n List<String> result = new ArrayLis... | 10 | 0 | ['Java'] | 5 |
design-an-ordered-stream | C++ easiest solutin | c-easiest-solutin-by-aparna_g-muhj | \nclass OrderedStream {\npublic:\n vector<string> stream ; //to get input\n int i=0;\n OrderedStream(int n) {\n stream.resize(n); //change the s | aparna_g | NORMAL | 2020-11-21T13:36:32.870581+00:00 | 2020-11-21T13:36:32.870609+00:00 | 1,632 | false | ```\nclass OrderedStream {\npublic:\n vector<string> stream ; //to get input\n int i=0;\n OrderedStream(int n) {\n stream.resize(n); //change the size of the vector when orderedStream is called\n }\n \n vector<string> insert(int id, string value) {\n vector<string> result;\n strea... | 8 | 1 | ['C', 'C++'] | 0 |
design-an-ordered-stream | C++||Easy to Understand | ceasy-to-understand-by-return_7-vent | ```\nclass OrderedStream {\npublic:\n vector stream;\n int i=0;\n OrderedStream(int n) \n {\n stream.resize(n);\n \n }\n \n v | return_7 | NORMAL | 2022-09-08T14:50:58.363757+00:00 | 2022-09-08T14:50:58.363805+00:00 | 1,134 | false | ```\nclass OrderedStream {\npublic:\n vector<string> stream;\n int i=0;\n OrderedStream(int n) \n {\n stream.resize(n);\n \n }\n \n vector<string> insert(int idKey, string value)\n {\n vector<string> res;\n stream[idKey-1]=value;\n while(i<stream.size()&&stream... | 7 | 0 | ['C'] | 1 |
design-an-ordered-stream | super clear 🐍 illustrated explanation | super-clear-illustrated-explanation-by-w-mtkk | <-- please vote\n\n\n\n\nclass OrderedStream:\n\n def init(self, n: int):\n """ O(N)S"""\n self.arr = [None] * (n + 1)\n self.ptr = 1\n\ | wilmerkrisp | NORMAL | 2022-05-16T12:57:59.080598+00:00 | 2022-05-16T12:57:59.080626+00:00 | 612 | false | <-- please vote\n\n\n\n\nclass OrderedStream:\n\n def __init__(self, n: int):\n """ O(N)S"""\n self.arr = [None] * (n + 1)\n self.ptr = 1\n\n def insert(self, idKey: int, value: str) ... | 7 | 0 | [] | 0 |
design-an-ordered-stream | Easiest C++ Code | easiest-c-code-by-baibhavsingh07-o8cn | 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 | baibhavsingh07 | NORMAL | 2023-05-31T12:51:37.468977+00:00 | 2023-05-31T12:51:37.469001+00:00 | 1,883 | 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(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\n<!-- Add your space complexity here, e.g. $$O... | 6 | 0 | ['Array', 'Design', 'Data Stream', 'C++'] | 1 |
design-an-ordered-stream | Python Easy to Understand Solution | python-easy-to-understand-solution-by-ra-gbet | \nclass OrderedStream:\n\n def __init__(self, n: int):\n self.val=[[] for i in range(n+1)]\n self.left=0\n\n def insert(self, id: int, value | ragav_1302 | NORMAL | 2020-11-15T06:05:44.557006+00:00 | 2020-11-15T06:05:44.557042+00:00 | 865 | false | ```\nclass OrderedStream:\n\n def __init__(self, n: int):\n self.val=[[] for i in range(n+1)]\n self.left=0\n\n def insert(self, id: int, value: str) -> List[str]:\n self.val[id-1]=value\n if self.left!=id-1:\n return []\n ans=[]\n while self.val[self.left]!=[]... | 6 | 0 | [] | 1 |
design-an-ordered-stream | notmy_OrderedStream | notmy_orderedstream-by-rinatmambetov-p5zc | # Intuition \n\n\n\n\n\n\n\n\n\n\n\n# Code\n\nclass OrderedStream {\n\tconstructor(n) {\n\t\tthis.pointer = 0;\n\t\tthis.list = [];\n\t}\n\n\tinsert(id, val) | RinatMambetov | NORMAL | 2023-05-09T15:34:33.612384+00:00 | 2023-05-09T15:34:33.612412+00:00 | 880 | 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 spa... | 5 | 0 | ['JavaScript'] | 0 |
design-an-ordered-stream | C++ Easy Solution || Clean Code | c-easy-solution-clean-code-by-dee_stroye-g2b2 | \nclass OrderedStream {\npublic:\n int pointer = 0;\n vector<string>stream;\n \n OrderedStream(int n) {\n stream.resize(n);\n }\n \n | dee_stroyer | NORMAL | 2022-01-10T16:29:59.533413+00:00 | 2022-01-10T16:29:59.533454+00:00 | 871 | false | ```\nclass OrderedStream {\npublic:\n int pointer = 0;\n vector<string>stream;\n \n OrderedStream(int n) {\n stream.resize(n);\n }\n \n vector<string> insert(int idKey, string value) {\n vector<string>ans;\n \n stream[idKey-1] = value;\n \n while(pointer<st... | 5 | 0 | ['C', 'C++'] | 1 |
design-an-ordered-stream | JavaScript Simple Array Solution - 98% Faster, 27% Less Memory | javascript-simple-array-solution-98-fast-mfrm | I didn\'t use a hash table, I just initialized an array with a pointer and when the pointer had data I push it into a result array and returned the result array | rachelsalazar | NORMAL | 2021-08-19T23:34:44.491701+00:00 | 2021-08-19T23:42:42.606252+00:00 | 1,095 | false | I didn\'t use a hash table, I just initialized an array with a pointer and when the pointer had data I push it into a result array and returned the result array. See below:\n```\n/**\n * @param {number} n\n */\nvar OrderedStream = function(n) {\n // initialize array\n this.arr = [];\n // start pointer at index of 0\... | 5 | 0 | ['JavaScript'] | 1 |
design-an-ordered-stream | Bad description (C++ : solved using animation in example) | bad-description-c-solved-using-animation-3267 | \nclass OrderedStream {\npublic:\n vector<string> vec;\n int n, pointer;\n OrderedStream(int n) {\n vec.resize(n+1, "");\n this->n | mazhar_mik | NORMAL | 2021-08-11T13:23:00.120532+00:00 | 2021-08-11T13:23:00.120561+00:00 | 331 | false | ```\nclass OrderedStream {\npublic:\n vector<string> vec;\n int n, pointer;\n OrderedStream(int n) {\n vec.resize(n+1, "");\n this->n = n;\n this->pointer = 1;\n }\n \n vector<string> insert(int idKey, string value) {\n vector<string> result;\n vec[idKey] = val... | 5 | 0 | [] | 0 |
design-an-ordered-stream | C++ solution with explanation | c-solution-with-explanation-by-rmallela0-cmrv | \nclass OrderedStream {\nprivate:\n std::vector<string> stream;\n int readIdx;\n \npublic:\n OrderedStream(int n) {\n // resize the vector st | rmallela0426 | NORMAL | 2021-04-15T22:03:56.008283+00:00 | 2021-04-15T22:03:56.008312+00:00 | 397 | false | ```\nclass OrderedStream {\nprivate:\n std::vector<string> stream;\n int readIdx;\n \npublic:\n OrderedStream(int n) {\n // resize the vector stream\n stream.resize(n);\n // Initialize the readIdx to starting point\n readIdx = 0; \n }\n \n vector<string> insert(in... | 5 | 0 | [] | 0 |
design-an-ordered-stream | C++ Solution | Bloomberg High Frequency Problem | c-solution-bloomberg-high-frequency-prob-3v75 | This is the Bloomberg High Frequency Problem. They asked the same question wrapping it as printing package of a UDP process. \n\n\nclass OrderedStream {\nprivat | vwo50 | NORMAL | 2021-03-14T22:18:35.220779+00:00 | 2021-03-14T22:18:35.220818+00:00 | 631 | false | This is the Bloomberg High Frequency Problem. They asked the same question wrapping it as printing package of a UDP process. \n\n```\nclass OrderedStream {\nprivate:\n int id = 1; \n \n unordered_map<int, string> m;\npublic:\n OrderedStream(int n) {\n \n }\n \n vector<string> insert(int idKe... | 5 | 0 | ['C'] | 0 |
design-an-ordered-stream | Golang solution | golang-solution-by-sisigogo-ug30 | \ntype OrderedStream struct {\n ptr int\n list []string\n}\n\nfunc Constructor(n int) OrderedStream {\n return OrderedStream{0,make([]string,n)}\n}\n\n | sisigogo | NORMAL | 2020-11-19T18:19:43.317731+00:00 | 2020-11-19T18:19:43.317774+00:00 | 247 | false | ```\ntype OrderedStream struct {\n ptr int\n list []string\n}\n\nfunc Constructor(n int) OrderedStream {\n return OrderedStream{0,make([]string,n)}\n}\n\n\nfunc (this *OrderedStream) Insert(id int, value string) []string {\n this.list[id-1] = value\n if this.list[this.ptr] == "" {\n return []strin... | 4 | 0 | ['Go'] | 0 |
design-an-ordered-stream | C++ Solution || HashMaps || Arrays✔✔ | c-solution-hashmaps-arrays-by-akanksha98-6zua | \n## MAPS\n\nclass OrderedStream {\npublic:\n map<int,string> mp;\n int count=1;\n OrderedStream(int n) {\n count=1;\n }\n vector<string> | akanksha984 | NORMAL | 2023-05-06T12:32:32.476260+00:00 | 2023-05-06T13:02:28.175120+00:00 | 680 | false | \n## MAPS\n```\nclass OrderedStream {\npublic:\n map<int,string> mp;\n int count=1;\n OrderedStream(int n) {\n count=1;\n }\n vector<string> insert(int idKey, string value) {\n mp.insert({idKey,value});\n vector<string> ans;\n for (auto vl: mp){\n if (vl.first==coun... | 3 | 0 | ['Array', 'Hash Table', 'Design', 'Data Stream', 'C++'] | 2 |
design-an-ordered-stream | Python solution with a hint before the solution. | python-solution-with-a-hint-before-the-s-r5ys | Approach\n Describe your approach to solving the problem. \nIf you don\'t want to go through my code, I suggest you to watch the example video and observe the " | kush_ishere | NORMAL | 2022-12-28T11:45:12.917984+00:00 | 2022-12-28T11:47:55.899291+00:00 | 1,869 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nIf you don\'t want to go through my code, I suggest you to watch the example video and observe the "ptr" and how it is incrementing and returning things based on the ptr value.\n\n# Code\n```\nclass OrderedStream:\n\n def __init__(self, n: int):\n ... | 3 | 0 | ['Python3'] | 0 |
design-an-ordered-stream | Java || O (n) || Explanation and code with comments | java-o-n-explanation-and-code-with-comme-vdrb | Even though the description may not be entirely clear, paying close attention to the attached GIF will help.\n\n1) A pointer starts at 0-th position (0-based)\n | kaushik_mitra | NORMAL | 2022-06-28T19:45:07.064242+00:00 | 2022-06-28T19:45:07.064285+00:00 | 846 | false | Even though the description may not be entirely clear, paying close attention to the attached GIF will help.\n\n1) A pointer starts at 0-th position (0-based)\n2) String data is inserted at K-th position (idKey minus 1)\n3) Try to move pointer all the way to right if locations are filled\n\n```\nclass OrderedStream {\n... | 3 | 0 | ['Java'] | 1 |
design-an-ordered-stream | Python: holding last min index | python-holding-last-min-index-by-ryabkin-223r | \nclass OrderedStream(object):\n\n def __init__(self, n):\n """\n :type n: int\n """\n self.values = [None] * n\n self.ret | ryabkin | NORMAL | 2021-12-06T15:34:04.979803+00:00 | 2021-12-06T15:34:38.939530+00:00 | 478 | false | ```\nclass OrderedStream(object):\n\n def __init__(self, n):\n """\n :type n: int\n """\n self.values = [None] * n\n self.returned_min = 0\n \n\n def insert(self, idKey, value):\n """\n :type idKey: int\n :type value: str\n :rtype: List[str]\n ... | 3 | 0 | ['Python'] | 0 |
design-an-ordered-stream | [JavaScript] Easy solution | javascript-easy-solution-by-joviho-ygru | ```\n/\n * @param {number} n\n */\nvar OrderedStream = function(n) {\n arr = new Array(n);\n plt = 0;\n};\n\n/ \n * @param {number} idKey \n * @param {str | JoviHo | NORMAL | 2021-09-09T04:00:34.508200+00:00 | 2021-09-09T04:00:34.508247+00:00 | 131 | false | ```\n/**\n * @param {number} n\n */\nvar OrderedStream = function(n) {\n arr = new Array(n);\n plt = 0;\n};\n\n/** \n * @param {number} idKey \n * @param {string} value\n * @return {string[]}\n */\nOrderedStream.prototype.insert = function(idKey, value) {\n arr[idKey-1] = value;\n let tempArr = [];\n for... | 3 | 0 | [] | 0 |
design-an-ordered-stream | Java 5 Lines Solution | java-5-lines-solution-by-ferman-d0oq | \nprivate String[] values;\nprivate int i = 0;\n\npublic OrderedStream(int n) {\n\tvalues = new String[n];\n}\n\npublic List<String> insert(int idKey, String va | ferman | NORMAL | 2021-05-03T12:16:32.058352+00:00 | 2021-05-03T12:16:32.058383+00:00 | 553 | false | ```\nprivate String[] values;\nprivate int i = 0;\n\npublic OrderedStream(int n) {\n\tvalues = new String[n];\n}\n\npublic List<String> insert(int idKey, String value) {\n\t// Below 5 lines do the magic\n\tvalues[idKey - 1] = value; \n\tList<String> res = new ArrayList<>();\n\twhile (i < values.length && values[i] !=... | 3 | 0 | ['Java'] | 0 |
design-an-ordered-stream | [Python3] Solution and most importantly - Question Explained | python3-solution-and-most-importantly-qu-iohq | Problem: Question is asking to return the stream of strings starting from the location idKey. \nIdea: Keep global variable self.loc; if the idKey is equal to se | vs152 | NORMAL | 2021-04-08T00:10:38.622596+00:00 | 2021-04-08T00:10:38.622645+00:00 | 408 | false | Problem: Question is asking to return the stream of strings starting from the location **idKey**. \nIdea: Keep global variable ```self.loc```; if the idKey is equal to ```self.loc``` then return the array of strings. Otherwise return ```[]```\n\nI hope this helps someone!\nP.S.: It\'s better to skip this question! ;p\n... | 3 | 1 | ['Python3'] | 0 |
design-an-ordered-stream | java simple | java-simple-by-rmanish0308-0g1a | \nclass OrderedStream {\n private int ptr;\n private String[] arr;\n public OrderedStream(int n) {\n arr = new String[n+1];\n ptr = 1;\n | rmanish0308 | NORMAL | 2021-04-02T06:11:36.112295+00:00 | 2021-04-02T06:11:36.112335+00:00 | 224 | false | ```\nclass OrderedStream {\n private int ptr;\n private String[] arr;\n public OrderedStream(int n) {\n arr = new String[n+1];\n ptr = 1;\n }\n \n public List<String> insert(int idKey, String value) {\n arr[idKey] = value;\n List<String> str = new ArrayList<>();\n wh... | 3 | 1 | [] | 0 |
design-an-ordered-stream | Simple Solution in Java | simple-solution-in-java-by-s34-kl7v | \nclass OrderedStream {\n private String[] s;\n private int next;\n public OrderedStream(int n) {\n s=new String[n+1];\n next=1;\n }\n | s34 | NORMAL | 2021-03-01T04:02:41.368613+00:00 | 2021-03-01T04:02:41.368672+00:00 | 164 | false | ```\nclass OrderedStream {\n private String[] s;\n private int next;\n public OrderedStream(int n) {\n s=new String[n+1];\n next=1;\n }\n \n public List<String> insert(int id, String value) {\n s[id]=value;\n List<String> tmp=new ArrayList<>();\n if(id==next){\n ... | 3 | 0 | [] | 1 |
design-an-ordered-stream | Python solution easy and straight forward | python-solution-easy-and-straight-forwar-afax | \nclass OrderedStream:\n def __init__(self, n: int):\n self.stream = [None]*(n+1)\n self.temp = 1\n\n def insert(self, id: int, value: str) | kadarsh2k00 | NORMAL | 2020-11-30T09:21:08.620518+00:00 | 2020-11-30T09:22:05.076333+00:00 | 890 | false | ```\nclass OrderedStream:\n def __init__(self, n: int):\n self.stream = [None]*(n+1)\n self.temp = 1\n\n def insert(self, id: int, value: str) -> List[str]:\n self.stream[id] = value\n ans = []\n while self.temp < len(self.stream) and self.stream[self.temp]:\n ans.app... | 3 | 0 | ['Python', 'Python3'] | 0 |
design-an-ordered-stream | C# - Store id value in simple array, main part is understanding question | c-store-id-value-in-simple-array-main-pa-w7jf | csharp\npublic class OrderedStream\n{\n string[] ordered;\n int ptr;\n\n public OrderedStream(int n)\n {\n ordered = new string[n + 1];\n | christris | NORMAL | 2020-11-15T04:04:58.969932+00:00 | 2020-11-15T04:04:58.969959+00:00 | 312 | false | ```csharp\npublic class OrderedStream\n{\n string[] ordered;\n int ptr;\n\n public OrderedStream(int n)\n {\n ordered = new string[n + 1];\n ptr = 1;\n }\n\n public IList<string> Insert(int id, string value)\n {\n ordered[id] = value;\n List<string> result = new List<str... | 3 | 0 | [] | 0 |
design-an-ordered-stream | 🔥Beats 93.56%🔥✅Easy (C++/Java/Python) Solution With Detailed Explanation✅ | beats-9356easy-cjavapython-solution-with-7864 | Intuition\nThe intuition of OrderedStream class in C++ is designed to model an ordered stream of strings where the strings are inserted at specific positions, a | suyogshete04 | NORMAL | 2024-02-20T03:22:24.071041+00:00 | 2024-02-20T03:23:33.318042+00:00 | 586 | false | # Intuition\nThe intuition of `OrderedStream` class in C++ is designed to model an ordered stream of strings where the strings are inserted at specific positions, and contiguous blocks of strings are returned from the point of insertion if they form a sequence without gaps. Let\'s analyze the approach and complexity of... | 2 | 0 | ['C++'] | 0 |
design-an-ordered-stream | Solution with Runtime: 97.1% JAVA | solution-with-runtime-971-java-by-nyuton-oc1f | 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 | nyutonov_sh | NORMAL | 2023-06-29T17:10:58.889950+00:00 | 2023-06-29T17:11:44.787831+00:00 | 375 | 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)$$ --... | 2 | 0 | ['Java'] | 0 |
design-an-ordered-stream | Easy Java Solution Beats 99% onine submissions | easy-java-solution-beats-99-onine-submis-r6rw | Code\n\nclass OrderedStream {\n private String[] data;\n private int ptr;\n\n public OrderedStream(int n) {\n data = new String[n + 1];\n | Viraj_Patil_092 | NORMAL | 2023-06-11T17:51:40.916845+00:00 | 2023-06-11T17:51:40.916897+00:00 | 1,164 | false | # Code\n```\nclass OrderedStream {\n private String[] data;\n private int ptr;\n\n public OrderedStream(int n) {\n data = new String[n + 1];\n ptr = 1;\n }\n\n public String[] insert(int idKey, String value) {\n data[idKey] = value;\n List<String> res = new ArrayList<>();\n ... | 2 | 0 | ['Array', 'Hash Table', 'Design', 'Data Stream', 'Java'] | 0 |
design-an-ordered-stream | Python easy solution | python-easy-solution-by-nitw_rsa-mmqq | \nclass OrderedStream:\n\n def __init__(self, n: int):\n self.arr = [-1] * (n + 1)\n self.n = n\n self.ptr = 1\n\n\n def insert(self, | nitw_rsa | NORMAL | 2022-10-10T14:52:12.735269+00:00 | 2022-10-10T14:52:12.735298+00:00 | 1,627 | false | ```\nclass OrderedStream:\n\n def __init__(self, n: int):\n self.arr = [-1] * (n + 1)\n self.n = n\n self.ptr = 1\n\n\n def insert(self, idKey: int, value: str) -> List[str]:\n ans = []\n self.arr[idKey] = value\n \n while self.ptr <= self.n and self.arr[self.ptr] ... | 2 | 0 | [] | 0 |
design-an-ordered-stream | C++ solution with explanation | c-solution-with-explanation-by-maitreya4-hi08 | OG solution: https://leetcode.com/problems/design-an-ordered-stream/discuss/936090/C%2B%2B-Array\nFirst create a vector that will store the strings in the strea | maitreya47 | NORMAL | 2022-09-26T19:08:04.425685+00:00 | 2022-09-26T19:08:34.555023+00:00 | 1,623 | false | OG solution: https://leetcode.com/problems/design-an-ordered-stream/discuss/936090/C%2B%2B-Array\nFirst create a vector that will store the strings in the stream and over which we will iterate. Resize it to n+1 because the idKey will start from 1 and not 0.\nIn the insert function, assign the value to appropriate idKey... | 2 | 0 | ['C', 'C++'] | 0 |
design-an-ordered-stream | ✅C++||String Array || Easy Solution | cstring-array-easy-solution-by-indresh14-5y6g | \nclass OrderedStream {\npublic:\n string dp[1005];\n int ptr;\n OrderedStream(int n){\n ptr = 1;\n }\n \n vector<string> insert(int id | indresh149 | NORMAL | 2022-08-25T16:19:25.470687+00:00 | 2022-08-25T16:19:25.470724+00:00 | 631 | false | ```\nclass OrderedStream {\npublic:\n string dp[1005];\n int ptr;\n OrderedStream(int n){\n ptr = 1;\n }\n \n vector<string> insert(int idKey, string value) {\n dp[idKey] = value;\n if(dp[ptr] != ""){\n vector<string> ans;\n for(int i=ptr;i<=1005;i++){\n ... | 2 | 0 | ['C'] | 0 |
design-an-ordered-stream | JAVA well-formatted solution | java-well-formatted-solution-by-maxbaldi-rnln | The basic idea is to have a pointer and an array of strings and move the pointer with each insert if required.\nSpace: O(n), Time: O(n)\n\n\nimport java.util.Ar | maxbaldin | NORMAL | 2022-07-21T07:55:25.947556+00:00 | 2022-07-21T07:55:25.947611+00:00 | 580 | false | The basic idea is to have a pointer and an array of strings and move the pointer with each insert if required.\nSpace: O(n), Time: O(n)\n\n```\nimport java.util.ArrayList;\nimport java.util.List;\n\nclass OrderedStream {\n String[] stream;\n int ptr = 0;\n\n public OrderedStream(int n) {\n this.stream =... | 2 | 0 | ['Array', 'Java'] | 0 |
design-an-ordered-stream | python 3 || simple solution | python-3-simple-solution-by-derek-y-vqba | ```\nclass OrderedStream:\n\n def init(self, n: int):\n self.stream = [\'\'] * (n + 1)\n self.i = 0\n\n def insert(self, idKey: int, value: | derek-y | NORMAL | 2022-06-13T06:08:28.567167+00:00 | 2022-06-13T06:13:06.624721+00:00 | 719 | false | ```\nclass OrderedStream:\n\n def __init__(self, n: int):\n self.stream = [\'\'] * (n + 1)\n self.i = 0\n\n def insert(self, idKey: int, value: str) -> List[str]:\n self.stream[idKey - 1] = value\n res = []\n\n while self.stream[self.i]:\n res.append(self.stream[self.... | 2 | 0 | ['Array', 'Python', 'Python3'] | 1 |
design-an-ordered-stream | Python Commented beats 90% | Iteration, Codesplitting | python-commented-beats-90-iteration-code-3v8e | class OrderedStream:\n\n def init(self, n: int):\n self.arr = [None]*n # initialize the array for size n\n self.ptr = 0 # remeber where the stream | masterofnone | NORMAL | 2022-04-30T14:22:42.057155+00:00 | 2022-04-30T14:22:42.057193+00:00 | 575 | false | class OrderedStream:\n\n def __init__(self, n: int):\n self.arr = [None]*n # initialize the array for size n\n self.ptr = 0 # remeber where the stream pointer is at\n def get_chunk(self):\n chunk = []\n \n # Construct the next chunk by checking bounds, and ensuring value is not None\n ... | 2 | 0 | ['Python', 'Python3'] | 0 |
design-an-ordered-stream | Easy Typescript solution | easy-typescript-solution-by-buzzlightyea-e3x5 | \nclass OrderedStream {\n stream: string[]\n index: number;\n constructor(n: number) {\n this.stream = []\n this.index = 0;\n }\n\n | BuzzLightyearAldrin | NORMAL | 2022-04-23T18:29:31.265969+00:00 | 2022-04-23T18:29:31.266015+00:00 | 157 | false | ```\nclass OrderedStream {\n stream: string[]\n index: number;\n constructor(n: number) {\n this.stream = []\n this.index = 0;\n }\n\n insert(idKey: number, value: string): string[] {\n this.stream[idKey-1] = value;\n \n if(this.index === idKey-1) {\n while(t... | 2 | 0 | ['TypeScript'] | 0 |
design-an-ordered-stream | JAVA | Okay, sweetie, I know you think you’re explaining yourself, but you’re really not. | java-okay-sweetie-i-know-you-think-youre-3n2u | While I am reading the description, the voice of Penny from BIG BANG THEORY pop out.\n\n*Penny: Okay, sweetie, I know you think you\u2019re explaining yourself, | CrackItSean | NORMAL | 2022-04-15T04:28:40.419141+00:00 | 2022-04-15T04:28:40.419188+00:00 | 334 | false | While I am reading the description, the voice of Penny from BIG BANG THEORY pop out.\n\n****Penny: Okay, sweetie, I know you think you\u2019re explaining yourself, but you\u2019re really not.****\n\n```\nclass OrderedStream {\n String values[];\n int top=0;\n public OrderedStream(int n) {\n this.values=... | 2 | 0 | ['Java'] | 0 |
design-an-ordered-stream | 2 Easy to understand and simple Python3 Solutions using List and Dictionary | 2-easy-to-understand-and-simple-python3-86i21 | Method 1 - using List\n\n\nclass OrderedStream:\n\n def __init__(self, n: int):\n self.n = n\n self.val = [0]*n\n self.cur = 0\n\n de | harshitpoddar09 | NORMAL | 2022-02-13T19:36:12.289943+00:00 | 2022-02-13T19:36:12.289983+00:00 | 117 | false | **Method 1 - using List**\n\n```\nclass OrderedStream:\n\n def __init__(self, n: int):\n self.n = n\n self.val = [0]*n\n self.cur = 0\n\n def insert(self, idKey: int, value: str) -> List[str]:\n self.val[idKey-1] = value\n ans = []\n for i in range(self.cur,self.n):\n ... | 2 | 0 | [] | 0 |
design-an-ordered-stream | [JS] O(n) solution using hashmap | js-on-solution-using-hashmap-by-wintryle-3keb | \nclass OrderedStream {\n constructor(n) {\n this.map = new Map();\n this.key = 1;\n }\n insert(idKey, value) {\n this.map.set(idK | wintryleo | NORMAL | 2022-01-17T21:35:40.309373+00:00 | 2022-01-17T21:35:40.309418+00:00 | 423 | false | ```\nclass OrderedStream {\n constructor(n) {\n this.map = new Map();\n this.key = 1;\n }\n insert(idKey, value) {\n this.map.set(idKey, value);\t\t// add the key-value to the map\n const result = [];\n\t\t// until able to find the key in the map, add it to the resultant chunk\n\t\t... | 2 | 0 | ['JavaScript'] | 0 |
design-an-ordered-stream | Java Solution | java-solution-by-himanshubhoir-prl7 | \nclass OrderedStream {\n String[] arr;\n int ptr;\n public OrderedStream(int n) {\n arr = new String[n];\n ptr = 0;\n }\n \n pu | HimanshuBhoir | NORMAL | 2022-01-11T05:01:33.865099+00:00 | 2022-09-15T13:37:01.450206+00:00 | 336 | false | ```\nclass OrderedStream {\n String[] arr;\n int ptr;\n public OrderedStream(int n) {\n arr = new String[n];\n ptr = 0;\n }\n \n public List<String> insert(int idKey, String value) {\n arr[idKey-1] = value;\n List<String> list = new ArrayList<>();\n while(ptr < arr.l... | 2 | 0 | ['Java'] | 0 |
design-an-ordered-stream | SIMPLEST SOLUTION - C++ | simplest-solution-c-by-aadi_01-cdwd | \nclass OrderedStream {\npublic:\n vector<string> temporary;\n int currentPosition = 0;\n \n OrderedStream(int n) {\n temporary.resize(n);\n | aadi_01 | NORMAL | 2021-09-14T07:13:22.347345+00:00 | 2021-09-14T07:13:22.347377+00:00 | 195 | false | ```\nclass OrderedStream {\npublic:\n vector<string> temporary;\n int currentPosition = 0;\n \n OrderedStream(int n) {\n temporary.resize(n);\n }\n \n vector<string> insert(int idKey, string value) {\n vector<string> answer;\n temporary[ idKey - 1 ] = value;\n \n ... | 2 | 0 | [] | 0 |
design-an-ordered-stream | Java solution | java-solution-by-rkxyiiyk2-mg4o | \nclass OrderedStream {\n \n private int lo = 1;\n private String[] vals;\n\n public OrderedStream(int n) {\n vals = new String[n+1];\n }\ | rkxyiiyk2 | NORMAL | 2021-08-06T20:15:53.890263+00:00 | 2021-08-06T20:15:53.890295+00:00 | 449 | false | ```\nclass OrderedStream {\n \n private int lo = 1;\n private String[] vals;\n\n public OrderedStream(int n) {\n vals = new String[n+1];\n }\n \n public List<String> insert(int idKey, String value) {\n vals[idKey] = value;\n \n var retList = new ArrayList<String>();\n ... | 2 | 0 | ['Java'] | 0 |
design-an-ordered-stream | Python 93% fast solution - 5 lines only | python-93-fast-solution-5-lines-only-by-yopym | \nclass OrderedStream:\n\n def __init__(self, n: int):\n self.li=[0]*(n+1)\n self.ptr=0\n\n def insert(self, idKey: int, value: str) -> List | srhr17 | NORMAL | 2021-06-26T04:56:56.658277+00:00 | 2021-06-26T04:57:48.069807+00:00 | 575 | false | ```\nclass OrderedStream:\n\n def __init__(self, n: int):\n self.li=[0]*(n+1)\n self.ptr=0\n\n def insert(self, idKey: int, value: str) -> List[str]:\n self.li[idKey-1]=value\n end=self.li.index(0)\n k=self.ptr\n self.ptr=end\n return self.li[k:end]\n \n\n\n... | 2 | 0 | ['Python', 'Python3'] | 0 |
design-an-ordered-stream | C++ short and easy | c-short-and-easy-by-rap_tors-hoqo | \nclass OrderedStream {\npublic:\n vector<string>v;\n int i; //global index variable, to help us return output as vector gets filled\n OrderedStream(in | rap_tors | NORMAL | 2021-06-15T16:34:25.174528+00:00 | 2021-06-15T16:34:25.174591+00:00 | 341 | false | ```\nclass OrderedStream {\npublic:\n vector<string>v;\n int i; //global index variable, to help us return output as vector gets filled\n OrderedStream(int n) {\n v.resize(n, ""), i = 0;\n }\n vector<string> insert(int id, string value) {\n v[id - 1] = value; //since id is starting from 1\... | 2 | 0 | ['C++'] | 0 |
design-an-ordered-stream | Javascript : Simple And Concise Solution | javascript-simple-and-concise-solution-b-rg18 | \nvar OrderedStream = function(n) {\n this.pointer = 0;\n this.streamArray = new Array(n).fill(undefined);\n};\nOrderedStream.prototype.insert = function( | jadhamwi21 | NORMAL | 2021-05-22T15:11:59.287725+00:00 | 2021-05-22T15:12:21.468251+00:00 | 340 | false | ```\nvar OrderedStream = function(n) {\n this.pointer = 0;\n this.streamArray = new Array(n).fill(undefined);\n};\nOrderedStream.prototype.insert = function(idKey, value) {\n this.streamArray[idKey-1] = value;\n if(this.streamArray[this.pointer] === undefined){\n return [];\n }else{\n const... | 2 | 0 | ['JavaScript'] | 1 |
design-an-ordered-stream | Python :: Priority Queue | python-priority-queue-by-tuhinnn_py-4w4g | \nclass OrderedStream:\n\n def __init__(self, n: int):\n self.n = n\n self.ans = []\n \n self.counter = 1\n\n def insert(self, | tuhinnn_py | NORMAL | 2021-05-19T18:13:57.910383+00:00 | 2021-05-19T18:13:57.910432+00:00 | 111 | false | ```\nclass OrderedStream:\n\n def __init__(self, n: int):\n self.n = n\n self.ans = []\n \n self.counter = 1\n\n def insert(self, idKey: int, value: str) -> List[str]:\n ans = []\n heapq.heappush(self.ans, (idKey, value))\n \n x = heapq.heappop(self.ans) if ... | 2 | 0 | [] | 0 |
design-an-ordered-stream | Self explanatory O(n) easy to understand using Java | self-explanatory-on-easy-to-understand-u-hajt | \nclass OrderedStream {\n private String[] streams;\n private int counter = 0;\n public OrderedStream(int n) {\n streams = new String[n];\n } | i_m_groot | NORMAL | 2021-05-16T17:15:43.731143+00:00 | 2021-05-16T17:15:43.731186+00:00 | 266 | false | ```\nclass OrderedStream {\n private String[] streams;\n private int counter = 0;\n public OrderedStream(int n) {\n streams = new String[n];\n }\n \n public List<String> insert(int idKey, String value) {\n List<String> stream = new ArrayList<String>();\n streams[idKey-1] = value;\... | 2 | 0 | ['Array', 'Java'] | 0 |
design-an-ordered-stream | C++ faster than 95%, with explanation | c-faster-than-95-with-explanation-by-saj-8mir | Basic Idea\nAs we are given the total number of strings to be inserted, we can use an array of strings of length n to save them, according to their index (which | sajals5031 | NORMAL | 2021-05-16T09:08:50.620752+00:00 | 2021-05-16T09:08:50.620795+00:00 | 323 | false | ## Basic Idea\nAs we are given the total number of strings to be inserted, we can use an array of strings of length n to save them, according to their index (which is idKey -1). We also keep track of the next index to start the chunk building from, i.e the next unpublished string in the stream.\n\nThe stream is initial... | 2 | 0 | ['C'] | 2 |
design-an-ordered-stream | C++ Clean code | c-clean-code-by-hammerhead09-tfkd | ```\nclass OrderedStream {\n vector stream;\n int pointer;\npublic:\n OrderedStream(int n) {\n stream.resize(n + 1);\n pointer = 1;\n | hammerhead09 | NORMAL | 2021-01-27T22:52:08.367161+00:00 | 2021-01-27T22:52:08.367201+00:00 | 213 | false | ```\nclass OrderedStream {\n vector<string> stream;\n int pointer;\npublic:\n OrderedStream(int n) {\n stream.resize(n + 1);\n pointer = 1;\n }\n \n vector<string> insert(int id, string value) {\n stream[id] = value;\n vector<string> result;\n \n while (pointe... | 2 | 0 | [] | 0 |
design-an-ordered-stream | Python3 Solution | python3-solution-by-mxmb-2sr2 | Hard mode: take a shot every time you have to type self.\npython\nclass OrderedStream:\n \n def __init__(self, n: int):\n self.S = [None]*(n+1)\n | mxmb | NORMAL | 2021-01-12T23:56:32.079944+00:00 | 2021-01-12T23:57:36.697991+00:00 | 492 | false | Hard mode: take a shot every time you have to type `self`.\n```python\nclass OrderedStream:\n \n def __init__(self, n: int):\n self.S = [None]*(n+1)\n self.i = 1\n \n def insert(self, id: int, value: str) -> List[str]:\n self.S[id] = value\n while self.i < len(self.S):\n ... | 2 | 0 | ['Python', 'Python3'] | 0 |
design-an-ordered-stream | Java solution | java-solution-by-thilms-6qzf | private String[] arr;\n public OrderedStream(int n) {\n arr = new String[n];\n }\n\n public List<String> insert(int id, String value) {\n | thilms | NORMAL | 2020-12-26T19:44:35.222039+00:00 | 2020-12-26T19:47:04.297093+00:00 | 159 | false | ``` private String[] arr;\n public OrderedStream(int n) {\n arr = new String[n];\n }\n\n public List<String> insert(int id, String value) {\n int index = (id-1);\n\t\tList<String> list = new ArrayList<>();\n \n\t\tif(index < 0 || index > arr.length) return list;\n \n arr[in... | 2 | 0 | [] | 1 |
design-an-ordered-stream | C++ faster than 99.33%, memory usage less than 97.76% | c-faster-than-9933-memory-usage-less-tha-kthn | \nclass OrderedStream {\n public:\n // Initialize "pointer" (btw not an actual pointer) & stream vector\n int ptr=0;\n vector<string> st | hamptonjc | NORMAL | 2020-11-21T02:08:09.031549+00:00 | 2020-11-21T02:08:09.031583+00:00 | 309 | false | ```\nclass OrderedStream {\n public:\n // Initialize "pointer" (btw not an actual pointer) & stream vector\n int ptr=0;\n vector<string> stream;\n\n OrderedStream(int n) {\n // Constructor makes stream vector of size n\n vector<string> strm(n);\n stream = ... | 2 | 0 | ['C'] | 0 |
design-an-ordered-stream | C++ 98% | c-98-by-eridanoy-dmwy | \nclass OrderedStream {\npublic:\n OrderedStream(int n) {\n vec.resize(n);\n }\n \n vector<string> insert(int id, const string& value) {\n | eridanoy | NORMAL | 2020-11-17T22:56:52.798858+00:00 | 2020-11-17T22:58:44.217369+00:00 | 361 | false | ```\nclass OrderedStream {\npublic:\n OrderedStream(int n) {\n vec.resize(n);\n }\n \n vector<string> insert(int id, const string& value) {\n vec[--id]=value;\n vector<string> ans;\n while(pos<vec.size()) {\n if(vec[pos].empty()) break;\n ans.push_back(vec[p... | 2 | 0 | ['C'] | 0 |
design-an-ordered-stream | 100% fastest in C | 100-fastest-in-c-by-fabiengaubert-mm0o | \ntypedef struct {\n int ptr;\n int size;\n char** value;\n} OrderedStream;\n\n\nOrderedStream* orderedStreamCreate(int n) {\n OrderedStream *ordere | fabiengaubert | NORMAL | 2020-11-17T12:37:12.400439+00:00 | 2020-11-17T12:37:12.400475+00:00 | 292 | false | ```\ntypedef struct {\n int ptr;\n int size;\n char** value;\n} OrderedStream;\n\n\nOrderedStream* orderedStreamCreate(int n) {\n OrderedStream *orderedStream = (OrderedStream*)malloc(sizeof(OrderedStream));\n orderedStream->ptr=1;\n orderedStream->size=n;\n orderedStream->value=(char**)malloc(size... | 2 | 0 | [] | 0 |
design-an-ordered-stream | 65ms Java faster than 100% w/Comments | 65ms-java-faster-than-100-wcomments-by-r-c6c6 | If any question feel free to ask.\n\nclass OrderedStream {\n String[] arr; //Stores the String values in the id\'th index.\n int size; //size of orderedst | reuzun | NORMAL | 2020-11-15T13:44:01.083368+00:00 | 2020-11-15T13:45:10.992296+00:00 | 345 | false | If any question feel free to ask.\n```\nclass OrderedStream {\n String[] arr; //Stores the String values in the id\'th index.\n int size; //size of orderedstream\n int ptr; //pointer to hold current position\n \n public OrderedStream(int n) {\n size = n;\n arr = new String[size+1]; //size+1... | 2 | 0 | ['Java'] | 1 |
design-an-ordered-stream | Java Simple HashMap | java-simple-hashmap-by-vikrant_pc-sqra | \nclass OrderedStream {\n int index = 1;\n Map<Integer, String> map = new HashMap<>();\n \n public OrderedStream(int n) {\n }\n \n public L | vikrant_pc | NORMAL | 2020-11-15T08:15:36.578943+00:00 | 2020-11-15T08:20:31.545196+00:00 | 243 | false | ```\nclass OrderedStream {\n int index = 1;\n Map<Integer, String> map = new HashMap<>();\n \n public OrderedStream(int n) {\n }\n \n public List<String> insert(int id, String value) {\n map.put(id, value);\n List<String> result = new ArrayList<>();\n while (map.containsKey(ind... | 2 | 0 | [] | 0 |
design-an-ordered-stream | Javascript solution using array - 184 ms | javascript-solution-using-array-184-ms-b-huo5 | \nvar OrderedStream = function(n) {\n this.arr = new Array(n);\n this.index = 0;\n};\n\nOrderedStream.prototype.insert = function(id, value) {\n this.a | eforce | NORMAL | 2020-11-15T06:46:10.921801+00:00 | 2020-11-15T06:46:10.921833+00:00 | 214 | false | ```\nvar OrderedStream = function(n) {\n this.arr = new Array(n);\n this.index = 0;\n};\n\nOrderedStream.prototype.insert = function(id, value) {\n this.arr[id - 1] = value;\n const result = [];\n while (this.arr[this.index]) {\n result.push(this.arr[this.index++]);\n }\n return result;\n};\... | 2 | 0 | [] | 0 |
design-an-ordered-stream | Golang solution with explanation of problem | golang-solution-with-explanation-of-prob-duiq | Intuition\nMy intuition here was to look at tons of solutions on youtube & leetcode until I could understand the problem because the description made no mention | gcrobertson | NORMAL | 2023-12-17T04:03:34.390690+00:00 | 2023-12-17T04:03:34.390717+00:00 | 17 | false | # Intuition\nMy intuition here was to look at tons of solutions on youtube & leetcode until I could understand the problem because the description made no mention of a pointer.\n\n# Approach\nWhat the description to the problem completely leaves out, is that our class needs two things:\n- A container for the values\n ... | 1 | 0 | ['Go'] | 0 |
design-an-ordered-stream | 86ms Beats 94.33% of users with C++ | 86ms-beats-9433-of-users-with-c-by-surya-j1bg | Intuition\nThe problem involves designing a data structure to handle an ordered stream of strings. My initial thoughts are to use a vector to store the strings | surya_26 | NORMAL | 2023-11-22T21:39:19.122222+00:00 | 2023-11-22T21:39:19.122261+00:00 | 208 | false | # Intuition\nThe problem involves designing a data structure to handle an ordered stream of strings. My initial thoughts are to use a vector to store the strings and a pointer to keep track of the current position in the stream.\n\n# Approach\n1. **Initialization:**\n - Create a vector `data` to store the strings. Th... | 1 | 0 | ['Array', 'Hash Table', 'Design', 'Data Stream', 'C++'] | 0 |
design-an-ordered-stream | Decent results. | decent-results-by-domarx-9e9e | Intuition\n Describe your first thoughts on how to solve this problem. \nWhen idKey - 1 != ptr we simply return empty array of strings.\nWhen idKey - 1 == ptr w | domarx | NORMAL | 2023-07-16T10:24:24.933907+00:00 | 2023-07-16T10:24:24.933928+00:00 | 13 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWhen `idKey - 1 != ptr` we simply return empty array of strings.\nWhen `idKey - 1 == ptr` we iterate through array until we find an empty slot. Collect all strings in range of `ptr - idKey - 1`.\n\n# Complexity\n- Time complexity: O(n)\n<... | 1 | 0 | ['C'] | 0 |
design-an-ordered-stream | C# using array | c-using-array-by-dmitriy-maksimov-j6sg | Code\n\npublic class OrderedStream\n{\n private readonly string?[] _data;\n private int _ptr;\n\n public OrderedStream(int n)\n {\n _data = n | dmitriy-maksimov | NORMAL | 2023-06-14T10:45:27.856024+00:00 | 2023-06-14T10:45:27.856058+00:00 | 181 | false | # Code\n```\npublic class OrderedStream\n{\n private readonly string?[] _data;\n private int _ptr;\n\n public OrderedStream(int n)\n {\n _data = new string[n + 1];\n _ptr = 1;\n }\n\n public IList<string> Insert(int idKey, string value)\n {\n _data[idKey] = value;\n var ... | 1 | 0 | ['C#'] | 0 |
design-an-ordered-stream | Dart Solution | dart-solution-by-ahmedwafik-slxq | \nclass OrderedStream {\n late final List<String> data;\n int pointer = 0;\n\n OrderedStream(int n) {\n data = List<String>.filled(n, \'\');\n }\n | AhmedWafik | NORMAL | 2023-05-11T11:14:53.163676+00:00 | 2023-05-11T11:14:53.163706+00:00 | 17 | false | ```\nclass OrderedStream {\n late final List<String> data;\n int pointer = 0;\n\n OrderedStream(int n) {\n data = List<String>.filled(n, \'\');\n }\n \n List<String> insert(int idKey, String value) {\n data[idKey-1] = value;\n var result = <String>[];\n while(data[pointer]!=\'\' ){\n ... | 1 | 0 | ['Array', 'Dart'] | 0 |
design-an-ordered-stream | Easy Understandabe java Code~Trust me | easy-understandabe-java-codetrust-me-by-syxw7 | 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 | 2012027 | NORMAL | 2023-01-21T15:12:37.134544+00:00 | 2023-01-21T15:12:37.134590+00:00 | 64 | 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)$$ --... | 1 | 0 | ['Java'] | 1 |
design-an-ordered-stream | JAVA Solution | java-solution-by-ashanvvi-faqs | \n\n# Complexity\n- Time complexity:\nthe time complexity of the code is dominated by the insert() method, which is O(k) where k is the number of elements inser | ashanvvi | NORMAL | 2023-01-10T19:50:15.652078+00:00 | 2023-01-10T19:50:15.652114+00:00 | 39 | false | \n\n# Complexity\n- Time complexity:\nthe time complexity of the code is dominated by the insert() method, which is O(k) where k is the number of elements inserted so far.\n\n- Space complexity:\nThe space complexity of this code is O(n), where n is the number of elements that the stream can hold.\n\n# Code\n```\nclass... | 1 | 0 | ['Java'] | 0 |
design-an-ordered-stream | C++ Easy Solution | c-easy-solution-by-_kitish-855z | \nclass OrderedStream {\nprivate:\n vector<string> data;\n int i,x;\npublic:\n OrderedStream(int n) {\n x=n;\n data.resize(n,"");\n | _kitish | NORMAL | 2022-12-06T18:20:59.650175+00:00 | 2022-12-06T18:20:59.650215+00:00 | 692 | false | ```\nclass OrderedStream {\nprivate:\n vector<string> data;\n int i,x;\npublic:\n OrderedStream(int n) {\n x=n;\n data.resize(n,"");\n i=1;\n }\n \n vector<string> insert(int idKey, string value) {\n vector<string> ans;\n data[idKey-1] = value;\n if(idKey == i... | 1 | 0 | ['C++'] | 0 |
design-an-ordered-stream | 120ms | Go solution | 120ms-go-solution-by-kitanoyoru-ikjr | \n\ntype OrderedStream struct {\n hm map[int]string\n n int\n posPtr int \n}\n\nfunc Constructor(n int) OrderedStream {\n return OrderedStream {\n hm: m | kitanoyoru_ | NORMAL | 2022-11-29T01:23:50.247147+00:00 | 2022-11-29T01:23:50.247179+00:00 | 152 | false | \n```\ntype OrderedStream struct {\n hm map[int]string\n n int\n posPtr int \n}\n\nfunc Constructor(n int) OrderedStream {\n return OrderedStream {\n hm: make(map[int]string),\n n: n,\n posPtr: 1,\n }\n}\n\n\nfunc (this *OrderedStream) Insert(idKey int, value string) []string {\n this.hm[idKey] = value\... | 1 | 0 | ['Go'] | 0 |
design-an-ordered-stream | c++ | easy | fast | c-easy-fast-by-venomhighs7-h8h4 | \n\n# Code\n\n//from vishal_k78\nclass OrderedStream {\npublic:\n map<int,string> mp;\n int maxSize = -1,currIndex = 1;\n \n OrderedStream(int n) {\ | venomhighs7 | NORMAL | 2022-11-22T12:14:45.753891+00:00 | 2022-11-22T12:14:45.753932+00:00 | 48 | false | \n\n# Code\n```\n//from vishal_k78\nclass OrderedStream {\npublic:\n map<int,string> mp;\n int maxSize = -1,currIndex = 1;\n \n OrderedStream(int n) {\n maxSize = n;\n for(int i=1;i<=n;i++) mp[i] = "----";\n }\n \n vector<string> insert(int idKey, string value) {\n vector<strin... | 1 | 1 | ['C++'] | 0 |
design-an-ordered-stream | Rust | HashMap | rust-hashmap-by-tomijaga-anv7 | rust\nuse std::collections::HashMap;\n\n#[derive(Default)]\nstruct OrderedStream {\n ptr : usize,\n store : HashMap<usize, String>\n}\n\n\nimpl OrderedStr | tomijaga | NORMAL | 2022-10-17T03:14:49.166733+00:00 | 2022-10-17T03:14:49.166773+00:00 | 67 | false | ```rust\nuse std::collections::HashMap;\n\n#[derive(Default)]\nstruct OrderedStream {\n ptr : usize,\n store : HashMap<usize, String>\n}\n\n\nimpl OrderedStream {\n\n fn new(n: i32) -> Self {\n Default::default()\n }\n \n fn insert(&mut self, id_key: i32, value: String) -> Vec<String> {\n ... | 1 | 0 | ['Rust'] | 0 |
design-an-ordered-stream | Java O(N) time O(N) space, with explanation in code | java-on-time-on-space-with-explanation-i-ryma | \n// NOTE: \n// To understand the question, the concatenation of all the chunks should result in a list of the SORTED values.\n// That is why calling the functi | coco007wind | NORMAL | 2022-09-14T17:46:05.558918+00:00 | 2022-09-14T17:46:05.558963+00:00 | 487 | false | ```\n// NOTE: \n// To understand the question, the concatenation of all the chunks should result in a list of the SORTED values.\n// That is why calling the function of insert(3, "ccccc") will NOT return anything. \n// In other words, calling insert(1, "ccccc") returns "ccccc"\nclass OrderedStream {\n\n private Stri... | 1 | 0 | [] | 0 |
design-an-ordered-stream | Python3 [runtime faster than 90.82%, memory less than 93.18%] + testing | python3-runtime-faster-than-9082-memory-ufdu0 | ```\n"""\nexercise: 1656. Design an Ordered Stream\nhttps://leetcode.com/problems/design-an-ordered-stream/\ncompany: Bloomberg\n"""\n\n\n# Your OrderedStream o | kamildoescode | NORMAL | 2022-09-02T13:57:03.189384+00:00 | 2022-09-02T13:57:03.189422+00:00 | 965 | false | ```\n"""\nexercise: 1656. Design an Ordered Stream\nhttps://leetcode.com/problems/design-an-ordered-stream/\ncompany: Bloomberg\n"""\n\n\n# Your OrderedStream object will be instantiated and called as such:\n# obj = OrderedStream(n)\n# param_1 = obj.insert(idKey,value)\n\nclass OrderedStream:\n\n def __init__(self, ... | 1 | 0 | ['Python', 'Python3'] | 1 |
design-an-ordered-stream | Rust idiomatic solution | rust-idiomatic-solution-by-pierrewang-fn8a | \nstruct OrderedStream {\n arr: Vec<Option<String>>,\n ptr: usize\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need | pierrewang | NORMAL | 2022-08-29T23:53:20.603928+00:00 | 2022-08-29T23:54:57.626073+00:00 | 122 | false | ```\nstruct OrderedStream {\n arr: Vec<Option<String>>,\n ptr: usize\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl OrderedStream {\n\n fn new(n: i32) -> Self {\n Self {\n arr: vec![None... | 1 | 0 | ['Rust'] | 1 |
design-an-ordered-stream | C++ 💪 Based Solution to terrible problem 💪 with explanation | Beats 150% | c-based-solution-to-terrible-problem-wit-qlzp | \nclass OrderedStream {\nprivate:\n int k; //pointer to min index\n vector<string> chunks; //chunky boy\npublic:\n OrderedStream(int n) {\n k = | rojasdaniel94 | NORMAL | 2022-08-23T05:23:49.529175+00:00 | 2022-08-23T05:23:49.529217+00:00 | 119 | false | ```\nclass OrderedStream {\nprivate:\n int k; //pointer to min index\n vector<string> chunks; //chunky boy\npublic:\n OrderedStream(int n) {\n k = 1; //init to first pos\n \n for(int i = 0; i < n; i++) {\n chunks.push_back("-1"); //init all pos to -1 (unvisited)\n }\n ... | 1 | 0 | [] | 0 |
design-an-ordered-stream | SIMPLE C++ SOLUTION | simple-c-solution-by-ke4e-ypay | \nclass OrderedStream {\npublic:\n vector<string> s;\n int ptr=1;\n OrderedStream(int n) {\n s.resize(n+1);\n }\n \n vector<string> ins | ke4e | NORMAL | 2022-08-21T06:31:59.173211+00:00 | 2022-08-21T06:31:59.173256+00:00 | 215 | false | ```\nclass OrderedStream {\npublic:\n vector<string> s;\n int ptr=1;\n OrderedStream(int n) {\n s.resize(n+1);\n }\n \n vector<string> insert(int idKey, string value) {\n s[idKey]=value;\n vector<string> res;\n while(ptr<s.size() && !s[ptr].empty())\n res.push_ba... | 1 | 0 | ['C'] | 0 |
design-an-ordered-stream | c++ easy straightforward | c-easy-straightforward-by-colorfulpencil-fuzh | \nclass OrderedStream {\npublic:\n \n vector<string> orderedStream; \n \n int start;\n \n OrderedStream(int n) {\n for(int i=0; i<n; i+ | colorfulpencil | NORMAL | 2022-08-20T15:38:51.581705+00:00 | 2022-08-20T15:38:51.581736+00:00 | 338 | false | ```\nclass OrderedStream {\npublic:\n \n vector<string> orderedStream; \n \n int start;\n \n OrderedStream(int n) {\n for(int i=0; i<n; i++){\n orderedStream.push_back("");\n }\n \n start = 0;\n }\n \n vector<string> insert(int idKey, string value) {\n ... | 1 | 0 | ['C', 'C++'] | 0 |
design-an-ordered-stream | C++ || Easy || Global pointer | c-easy-global-pointer-by-user3405ye-djpp | We just need a global pointer to store the last index till which the elements have been printed or sent to the output stream. The only way to do it (approach th | user3405Ye | NORMAL | 2022-07-18T18:42:56.049713+00:00 | 2022-07-18T18:42:56.049757+00:00 | 178 | false | We just need a **global pointer** to store the **last index** till which the elements have been printed or sent to the output stream. The only way to do it (approach the problem) is in a linear fashion, from the starting index. Hence, the logic of the solution.\n**Please upvote if you find the solution good.\n*Thank Yo... | 1 | 0 | ['C', 'C++'] | 0 |
design-an-ordered-stream | c++ || Easy | c-easy-by-aabargaje-u90l | \nclass OrderedStream {\npublic:\n\n\t// Keep track how many values we have returned alredy.\n int startIndex = 0;\n vector<string> val;\n \n Ordere | aabargaje | NORMAL | 2022-07-09T04:59:31.272148+00:00 | 2022-07-09T04:59:31.272191+00:00 | 137 | false | ```\nclass OrderedStream {\npublic:\n\n\t// Keep track how many values we have returned alredy.\n int startIndex = 0;\n vector<string> val;\n \n OrderedStream(int n) {\n val.resize(n+1,"");\n }\n \n vector<string> insert(int idKey, string value) {\n vector<string> ans;\n val[id... | 1 | 0 | ['C'] | 0 |
design-an-ordered-stream | Reverse engineered solution to understand the problem LOL | reverse-engineered-solution-to-understan-3ufx | The problem description is so unclear that to finally understand what the heck author is asking for I had to find some solution here on discussion and reverse e | trpaslik | NORMAL | 2022-05-19T17:30:50.706433+00:00 | 2022-05-19T17:30:50.706461+00:00 | 110 | false | The problem description is so unclear that to finally understand **what the heck author is asking for** I had to find some solution here on discussion and reverse engineer it back to the problem description. \n\nDo you guys also find the unstoppable animated gif so annoying?\n\nThis is surly the most frustraifing "easy... | 1 | 0 | [] | 1 |
design-an-ordered-stream | [C++] elegant solution | c-elegant-solution-by-kristijan1996-vq4r | It is quite hard to understand the requirements at first, but the animation makes it easier.\nSo, we know in advance that we will be having an array of strings | kristijan1996 | NORMAL | 2022-05-10T17:19:11.326187+00:00 | 2022-05-21T08:01:29.476309+00:00 | 215 | false | It is quite hard to understand the requirements at first, but the animation makes it easier.\nSo, we know in advance that we will be having an array of strings of length *n*, and therefore\nthe constructor allocates a vector of empty strings. That is quite easy.\n\nInserting a value is also easy, since it is guaranteed... | 1 | 0 | ['C', 'C++'] | 1 |
design-an-ordered-stream | c++ | Array | easy | c-array-easy-by-srv-er-se1h | \nclass OrderedStream {\npublic:\n vector<string>v;\n int id=1;\n OrderedStream(int n) {\n v=vector<string>(n+1,"");\n }\n \n vector<st | srv-er | NORMAL | 2022-04-21T04:50:54.791218+00:00 | 2022-04-21T04:50:54.791260+00:00 | 164 | false | ```\nclass OrderedStream {\npublic:\n vector<string>v;\n int id=1;\n OrderedStream(int n) {\n v=vector<string>(n+1,"");\n }\n \n vector<string> insert(int idKey, string value) {\n v[idKey]=value;\n vector<string> ans;\n while(id<v.size() && v[id]!="")ans.push_back(v[id++]);... | 1 | 0 | ['Array', 'C'] | 1 |
design-an-ordered-stream | [C++/Python] vector based hashmap & global tracking index | cpython-vector-based-hashmap-global-trac-hztz | [C++/Python] vector based hashmap & global tracking index\n\nApproach 1: vector based hashmap + global tracking index (C++ version)\n\nclass OrderedStream { // | codedayday | NORMAL | 2022-04-15T07:29:35.916731+00:00 | 2022-04-15T07:29:35.916766+00:00 | 130 | false | [C++/Python] vector based hashmap & global tracking index\n\nApproach 1: vector based hashmap + global tracking index (C++ version)\n```\nclass OrderedStream { // BEST: use global index to track order 1~n\npublic:\n OrderedStream(int n):_vs(n+1), _idx(1) { }\n \n vector<string> insert(int idKey, string value) ... | 1 | 0 | ['C', 'Python'] | 0 |
design-an-ordered-stream | Simple python solution. Faster than 99.28% | simple-python-solution-faster-than-9928-m4flg | \nclass OrderedStream:\n\n def __init__(self, n: int):\n self.n = n\n self.start = 1\n self.ls = [None]*(n+1)\n\n def insert(self, id | amitbansal13 | NORMAL | 2022-03-06T17:19:34.197775+00:00 | 2022-03-06T17:19:34.197855+00:00 | 65 | false | ```\nclass OrderedStream:\n\n def __init__(self, n: int):\n self.n = n\n self.start = 1\n self.ls = [None]*(n+1)\n\n def insert(self, idKey: int, value: str) -> List[str]:\n self.ls[idKey] = value\n if self.ls[self.start] is None:\n return []\n \n ans = ... | 1 | 0 | [] | 0 |
design-an-ordered-stream | Java Solution With Explanation | java-solution-with-explanation-by-am0611-0cxd | \nclass OrderedStream {\n Map<Integer, String> stream;\n int ptr; // intialize ptr, then find the longest contiguous increasing sequence of ids from the p | am0611 | NORMAL | 2022-02-21T16:32:07.001751+00:00 | 2022-02-21T16:35:24.648274+00:00 | 230 | false | ```\nclass OrderedStream {\n Map<Integer, String> stream;\n int ptr; // intialize ptr, then find the longest contiguous increasing sequence of ids from the ptr\n public OrderedStream(int n) {\n this.stream = new HashMap<>();\n this.ptr = 1;\n }\n \n public List<String> insert(int idKey, ... | 1 | 0 | ['Java'] | 0 |
design-an-ordered-stream | Java, HashMap solution. | java-hashmap-solution-by-botir_adoshboye-3m5s | \nclass OrderedStream {\n\n Map<Integer, String> store;\n int lastIndex = 0;\n\n public OrderedStream(int n) {\n store = new HashMap<>(n);\n | botir_adoshboyev | NORMAL | 2022-02-15T11:30:19.273604+00:00 | 2022-02-15T11:30:19.273633+00:00 | 185 | false | ```\nclass OrderedStream {\n\n Map<Integer, String> store;\n int lastIndex = 0;\n\n public OrderedStream(int n) {\n store = new HashMap<>(n);\n }\n\n public List<String> insert(int idKey, String value) {\n List<String> res = new ArrayList<>();\n store.put(idKey, value);\n whil... | 1 | 0 | ['Java'] | 0 |
design-an-ordered-stream | Cpp Solution | cpp-solution-by-rautela-rse2 | \nclass OrderedStream {\n vector<string> strm;\n int cptr = 0;\npublic:\n OrderedStream(int n) {\n strm.resize(n);\n }\n \n vector<stri | rautela | NORMAL | 2022-02-13T09:31:58.012525+00:00 | 2022-02-13T09:31:58.012557+00:00 | 55 | false | ```\nclass OrderedStream {\n vector<string> strm;\n int cptr = 0;\npublic:\n OrderedStream(int n) {\n strm.resize(n);\n }\n \n vector<string> insert(int idKey, string value) {\n strm[idKey - 1] = value;\n vector<string> rstrm;\n while(cptr < strm.size() and strm[cptr] != ""... | 1 | 0 | [] | 0 |
design-an-ordered-stream | [Python] Design an Ordered Stream | python-design-an-ordered-stream-by-a_m_r-ck71 | I just need help with the design , if it can be improved.\n\n\nclass OrderedStream:\n\n def __init__(self, n: int):\n self.n = n\n self.dp = {i | a_m_rohit | NORMAL | 2022-02-06T13:39:42.469176+00:00 | 2022-02-06T13:39:42.469210+00:00 | 154 | false | I just need help with the design , if it can be improved.\n\n```\nclass OrderedStream:\n\n def __init__(self, n: int):\n self.n = n\n self.dp = {i:[] for i in range(1,self.n+1)}\n self.i = 1\n\n def insert(self, idKey: int, value: str) -> List[str]:\n (self.dp[idKey]).insert(0,value)\n... | 1 | 1 | [] | 0 |
design-an-ordered-stream | Rust solution with HashMap | rust-solution-with-hashmap-by-kuskus87-ok3o | Since there is only one rust-tagged solution for this problem, I will post another one which is \ntaken from here https://rustgym.com/leetcode/1656\n\nrust\nuse | kuskus87 | NORMAL | 2022-02-01T10:27:17.525344+00:00 | 2022-02-01T10:27:17.525386+00:00 | 122 | false | Since there is only one rust-tagged solution for this problem, I will post another one which is \ntaken from here https://rustgym.com/leetcode/1656\n\n```rust\nuse std::collections::HashMap;\n\nstruct OrderedStream {\n kv: HashMap<i32, String>,\n n: i32, \n i: i32,\n}\n\n/** \n * `&self` means the method takes... | 1 | 0 | ['Rust'] | 0 |
design-an-ordered-stream | Python solution (based on heap) | python-solution-based-on-heap-by-labdmit-imwy | \nimport heapq\n\nclass OrderedStream:\n\n def __init__(self, n: int):\n self.idx = 1\n self.heap = []\n\n def insert(self, idKey: int, valu | labdmitriy | NORMAL | 2022-01-05T18:09:58.118918+00:00 | 2022-01-05T18:09:58.118965+00:00 | 223 | false | ```\nimport heapq\n\nclass OrderedStream:\n\n def __init__(self, n: int):\n self.idx = 1\n self.heap = []\n\n def insert(self, idKey: int, value: str) -> List[str]:\n result = []\n \n if idKey == self.idx:\n result.append(value)\n self.idx += 1\n ... | 1 | 0 | ['Heap (Priority Queue)', 'Python'] | 1 |
design-an-ordered-stream | python3 solution | python3-solution-by-peter-pan-98fk | python\nclass OrderedStream:\n\n def __init__(self, n: int):\n self.index=0\n self.lt=[None]*n\n def insert(self, idKey: int, value: str) -> | peter-pan | NORMAL | 2022-01-03T01:52:00.744063+00:00 | 2022-01-03T01:52:00.744102+00:00 | 149 | false | ```python\nclass OrderedStream:\n\n def __init__(self, n: int):\n self.index=0\n self.lt=[None]*n\n def insert(self, idKey: int, value: str) -> List[str]:\n self.lt[idKey-1]=value\n if idKey!=self.index+1:\n return []\n num=0\n output=list()\n for ele in... | 1 | 0 | [] | 0 |
design-an-ordered-stream | Java || Explained the confusing description || Clean Solution | java-explained-the-confusing-description-j6un | // Confusing descriptoin. Here is what I understood from the GIF\n// when insert() is called, return the longest list that starts at index of pointer. If there | ICodeToSurvive | NORMAL | 2021-12-27T22:36:10.015899+00:00 | 2021-12-27T22:36:10.015946+00:00 | 198 | false | // Confusing descriptoin. Here is what I understood from the GIF\n// when insert() is called, return the longest list that starts at index of pointer. If there is not an elemnt at pointer(start), then return empty list\n\n// The POINTER is the next START window\n\n// TC : O(N) -> avg run time -> since we iterate the ar... | 1 | 0 | [] | 0 |
design-an-ordered-stream | C++, vector | c-vector-by-aleksej2-6xfy | \nclass OrderedStream {\n vector<string> data;\n int N;\n int ptr;\npublic:\n OrderedStream(int n) : data(n), N{n}, ptr{1} {\n }\n \n vecto | aleksej2 | NORMAL | 2021-12-14T14:10:46.235086+00:00 | 2021-12-14T14:10:46.235125+00:00 | 125 | false | ```\nclass OrderedStream {\n vector<string> data;\n int N;\n int ptr;\npublic:\n OrderedStream(int n) : data(n), N{n}, ptr{1} {\n }\n \n vector<string> insert(int id, string value) {\n data[id-1] = move(value);\n vector<string> ret;\n if(ptr != id)\n return ret;\n ... | 1 | 0 | [] | 0 |
design-an-ordered-stream | C++ | T: O(n), S: O(n) | Vector approach | c-t-on-s-on-vector-approach-by-snowspire-ennp | \nclass OrderedStream final {\npublic:\n explicit OrderedStream() noexcept = default;\n explicit OrderedStream(const OrderedStream&) noexcept = default;\n | snowspire_ | NORMAL | 2021-11-30T20:46:33.007370+00:00 | 2021-11-30T20:46:33.007407+00:00 | 123 | false | ```\nclass OrderedStream final {\npublic:\n explicit OrderedStream() noexcept = default;\n explicit OrderedStream(const OrderedStream&) noexcept = default;\n\n OrderedStream(int n) : stream_(std::vector<std::string>(n, "")), current_index_(0) {}\n\n std::vector<std::string> insert(int id, std::string value)... | 1 | 0 | [] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.