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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
last-stone-weight | ✅ Java | Easy Solution Explained 📝 | Similar Questions | Beginner friendly | java-easy-solution-explained-similar-que-54vt | Intuition\nSince we need to choose heaviest two stones everytime, this is a clear hint to go for heap data structure. In java we implement heap via priority que | nikeMafia | NORMAL | 2023-04-24T05:52:06.381408+00:00 | 2023-05-01T06:28:29.176763+00:00 | 5,492 | false | # Intuition\nSince we need to choose heaviest two stones everytime, this is a clear hint to go for heap data structure. In java we implement heap via priority queue.\n\nSimilar questions for heap i faced in interviews.\nLC 347[ Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements/)\nLC 215[ Kt... | 35 | 0 | ['Heap (Priority Queue)', 'Java'] | 5 |
last-stone-weight | C++/Java/Python 6 Line Approach, Question Clarifications & Heap Cheatsheet | cjavapython-6-line-approach-question-cla-9ysd | If you are already familiar with priority_queue in C++ skip to the Approach section at the end\n### C++ Heap Guide/Cheatsheet\nIn C++ priority_queue is the impl | numbart | NORMAL | 2022-04-07T10:14:15.087870+00:00 | 2022-04-09T09:53:23.900659+00:00 | 4,452 | false | If you are already familiar with priority_queue in C++ skip to the Approach section at the end\n### C++ Heap Guide/Cheatsheet\nIn C++ [priority_queue](https://www.cplusplus.com/reference/queue/priority_queue/) is the implementation for heaps. If you have never used priority_queue before, you can get started by reading ... | 33 | 0 | ['C', 'Heap (Priority Queue)', 'Python', 'Java'] | 5 |
last-stone-weight | Easy to Understand | Heap Based | Faster | Simple | Python Solution | easy-to-understand-heap-based-faster-sim-bzkm | \ndef lastStoneWeight(self, stones: List[int]) -> int:\n stones = [-i for i in stones]\n heapq.heapify(stones)\n while len(stones)>1:\n | mrmagician | NORMAL | 2020-04-04T21:08:05.466078+00:00 | 2020-04-04T21:08:05.466132+00:00 | 3,548 | false | ```\ndef lastStoneWeight(self, stones: List[int]) -> int:\n stones = [-i for i in stones]\n heapq.heapify(stones)\n while len(stones)>1:\n first = abs(heapq.heappop(stones))\n second = abs(heapq.heappop(stones))\n if first != second:\n heapq.heappush(... | 33 | 3 | ['Heap (Priority Queue)', 'Python', 'Python3'] | 2 |
last-stone-weight | ✅ Java best intuitive solution || Priority Queue || 1ms 99% faster | java-best-intuitive-solution-priority-qu-bv1t | Code\njava\npublic int lastStoneWeight(int[] stones) {\n\tPriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());\n\tfor(int st: stones)\n\ | Chaitanya31612 | NORMAL | 2022-04-07T05:06:09.170025+00:00 | 2022-04-07T05:19:06.123504+00:00 | 2,823 | false | **Code**\n```java\npublic int lastStoneWeight(int[] stones) {\n\tPriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());\n\tfor(int st: stones)\n\t\tpq.offer(st);\n\n\twhile(pq.size() > 1) {\n\t\tint f = pq.poll();\n\t\tint s = pq.poll();\n\t\tif(f != s) \n\t\t\tpq.offer(f-s);\n\t}\n\n\treturn pq.i... | 31 | 1 | ['Heap (Priority Queue)', 'Java'] | 3 |
last-stone-weight | ✔️ [C++] SIMULATION 100% ໒( ͡ᵔ ▾ ͡ᵔ )७, Explained | c-simulation-100-2-v-7-explained-by-arto-szuu | UPVOTE if you like (\uD83C\uDF38\u25E0\u203F\u25E0), If you have any question, feel free to ask.\n\nTo solve this problem, we can conduct an actual simulation o | artod | NORMAL | 2022-04-07T01:49:42.246076+00:00 | 2022-04-07T17:04:53.293720+00:00 | 4,898 | false | **UPVOTE if you like (\uD83C\uDF38\u25E0\u203F\u25E0), If you have any question, feel free to ask.**\n\nTo solve this problem, we can conduct an actual simulation of the described process. Since we always need to use the heaviest stones, we can use a heap data structure for easy access to max elements.\n\nTime: **O(nlo... | 31 | 1 | ['C'] | 8 |
last-stone-weight | [Python3] Heapq (Priority Queue) | python3-heapq-priority-queue-by-pinkspid-36fw | Since we want the two largest stones each time, and heapq.pop() gives us the smallest each time, we just need to make every value of stones negative at the begi | pinkspider | NORMAL | 2020-04-12T07:15:09.709589+00:00 | 2020-04-15T05:54:36.244775+00:00 | 4,003 | false | Since we want the two largest stones each time, and heapq.pop() gives us the smallest each time, we just need to make every value of stones negative at the beginning.\n```\nimport heapq\nclass Solution:\n def lastStoneWeight(self, stones: List[int]) -> int:\n stones = [-val for val in stones]\n heapq.h... | 31 | 0 | [] | 9 |
last-stone-weight | Easy Solution Of JAVA 🔥C++🔥Beginner Friendly 🔥ArrayList | easy-solution-of-java-cbeginner-friendly-b1cp | \n\n# Code\nPLEASE UPVOTE IF YOU LIKE.\n\nclass Solution {\n public int lastStoneWeight(int[] stones)\n{\n\t\tArrayList<Integer> listStones = new ArrayList<>( | shivrastogi | NORMAL | 2023-04-24T00:46:26.025631+00:00 | 2023-04-24T00:46:26.025677+00:00 | 6,037 | false | \n\n# Code\nPLEASE UPVOTE IF YOU LIKE.\n```\nclass Solution {\n public int lastStoneWeight(int[] stones)\n{\n\t\tArrayList<Integer> listStones = new ArrayList<>();\n\t\tfor (int a : stones)\n\t\t\tlistStones.add(a);\n\n\t\twhile (true)\n\t\t{\n\t\t\tint min = Integer.MAX_VALUE;\n\t\t\tint max = Integer.MIN_VALUE;\n\t... | 28 | 6 | ['Array', 'C++', 'Java'] | 0 |
last-stone-weight | ☕ Java Solution | Let's learn when to use Heap (Priority Queue) 🔺 | java-solution-lets-learn-when-to-use-hea-htqg | Intuition\nAs soon as we understand that we need to repeatedly get a maximum/minimum value from an array, we can use Heap (Priority Queue).\n\nYou can use Minim | B10nicle | NORMAL | 2023-02-23T15:39:11.390879+00:00 | 2023-03-02T11:23:04.093264+00:00 | 1,659 | false | # Intuition\nAs soon as we understand that we need to repeatedly get a maximum/minimum value from an array, we can use Heap (Priority Queue).\n\nYou can use Minimum Heap like this:\n***PriorityQueue<Integer> minHeap = new PriorityQueue<>();***\n\nOr you can use Maximum Heap this way:\n***PriorityQueue<Integer> maxHeap ... | 25 | 0 | ['Heap (Priority Queue)', 'Java'] | 2 |
last-stone-weight | [Python] Heap Explained with Easy Code | python-heap-explained-with-easy-code-by-dx58p | Naive Approach\nThe naive approach to solve the question, would be:\n\n1. Sort the array in decreasing order\n2. Pop the first two elements, subtract them.\n3. | satyam_mishra13 | NORMAL | 2022-11-27T16:06:42.955252+00:00 | 2023-05-16T18:52:51.285542+00:00 | 1,358 | false | # Naive Approach\nThe naive approach to solve the question, would be:\n\n1. Sort the array in decreasing order\n2. Pop the first two elements, subtract them.\n3. If the difference is 0, then do nothing. Else, append the difference in the array\n4. Repeat the step 1, 2 and 3 until there is only one item left in the arra... | 24 | 0 | ['Heap (Priority Queue)', 'Python', 'Python3'] | 1 |
last-stone-weight | Simple Javascript Soluton ---> Recursion | simple-javascript-soluton-recursion-by-n-99ju | \nvar lastStoneWeight = function(stones) {\n if(stones.length < 2) return stones;\n stones.sort((a,b) => a-b);\n let a = stones.pop();\n let b = sto | nileshsaini_99 | NORMAL | 2021-09-18T08:32:00.195763+00:00 | 2021-09-18T08:32:00.195806+00:00 | 2,434 | false | ```\nvar lastStoneWeight = function(stones) {\n if(stones.length < 2) return stones;\n stones.sort((a,b) => a-b);\n let a = stones.pop();\n let b = stones.pop();\n stones.push(Math.abs(a-b));\n return lastStoneWeight(stones);\n};\n``` | 24 | 0 | ['Recursion', 'JavaScript'] | 3 |
last-stone-weight | [Javascript] Simple Priority Queue | javascript-simple-priority-queue-by-theh-ysp1 | \nvar lastStoneWeight = function(stones) {\n const queue = new MaxPriorityQueue();\n \n for (stone of stones) queue.enqueue(stone)\n \n while (qu | TheHankLee | NORMAL | 2022-06-07T19:25:16.065594+00:00 | 2022-06-07T19:25:56.135327+00:00 | 2,249 | false | ```\nvar lastStoneWeight = function(stones) {\n const queue = new MaxPriorityQueue();\n \n for (stone of stones) queue.enqueue(stone)\n \n while (queue.size() > 1) {\n let first = queue.dequeue().element;\n let second = queue.dequeue().element;\n if (first !== second) queue.enqueue(f... | 23 | 0 | ['Heap (Priority Queue)', 'JavaScript'] | 3 |
last-stone-weight | Shortest solution using Min Heap (PriorityQueue) | shortest-solution-using-min-heap-priorit-fuef | Step 1: Put the array into a min heap. To avoid creating a custom comparer, let\'s just revert priorities (-x).\nStep 2: Get the two "heaviest" stones from the | anikit | NORMAL | 2022-04-07T07:49:10.592302+00:00 | 2023-01-03T22:11:43.862661+00:00 | 1,382 | false | **Step 1:** Put the array into a min heap. To avoid creating a custom comparer, let\'s just revert priorities (`-x`).\n**Step 2:** Get the two "heaviest" stones from the heap and smash them together. If there is something left, put it back into the heap.\n\n```csharp\npublic int LastStoneWeight(int[] stones)\n{\n va... | 19 | 0 | ['Heap (Priority Queue)', 'C#'] | 3 |
last-stone-weight | ✅2 approaches: Sorting & Max Heap with explanations! | 2-approaches-sorting-max-heap-with-expla-gg00 | If you\u2019re interested in coding you can join my Discord Server, link in the comment section. Also if you find any mistakes please let me know. Thank you!\u2 | dhruba-datta | NORMAL | 2022-04-07T07:37:28.153660+00:00 | 2022-04-07T07:39:32.273176+00:00 | 1,768 | false | > **If you\u2019re interested in coding you can join my Discord Server, link in the comment section. Also if you find any mistakes please let me know. Thank you!\u2764\uFE0F**\n> \n\n\n---\n\n## Explanation:\n\n### Solution 01\n\n- ***Brute force solution*** //not recommended.\n- Here every iteration we\u2019re sorting... | 19 | 0 | ['C', 'Sorting', 'Heap (Priority Queue)', 'C++'] | 1 |
last-stone-weight | Java 100% time 100% space | java-100-time-100-space-by-robsalcedo-z5yj | ````\npublic int lastStoneWeight(int[] stones) {\n if(stones.length==1)return stones[0];\n Arrays.sort(stones);\n int y = stones.length-1;\ | robsalcedo | NORMAL | 2020-01-30T07:08:05.371240+00:00 | 2020-01-30T07:08:05.371273+00:00 | 1,804 | false | ````\npublic int lastStoneWeight(int[] stones) {\n if(stones.length==1)return stones[0];\n Arrays.sort(stones);\n int y = stones.length-1;\n int x = stones.length-2;\n while(x>=0){\n if(stones[x]==stones[y]){\n stones[x] = 0;\n stones[y] = 0;\n... | 19 | 1 | ['Java'] | 6 |
last-stone-weight | c++ priority_queue 100% time, short easy to understand | c-priority_queue-100-time-short-easy-to-d5v8r | \npriority_queue<int> pq(v.begin(),v.end());\n \n while(true)\n {\n if(pq.size() ==0) return 0;\n if(pq.size() ==1) | yuganhumyogi | NORMAL | 2019-08-24T15:09:16.467399+00:00 | 2019-08-24T15:09:16.467432+00:00 | 1,449 | false | ```\npriority_queue<int> pq(v.begin(),v.end());\n \n while(true)\n {\n if(pq.size() ==0) return 0;\n if(pq.size() ==1) return pq.top();\n int a = pq.top();\n pq.pop();\n int b = pq.top();\n pq.pop();\n if(a!=b) pq.p... | 18 | 2 | ['C', 'Heap (Priority Queue)'] | 1 |
last-stone-weight | ✅ [Python] 6 Lines || SortedList || Clean | python-6-lines-sortedlist-clean-by-linfq-6nzf | Please UPVOTE if you LIKE! \uD83D\uDE01\n\n\nfrom sortedcontainers import SortedList\n\n\nclass Solution(object):\n def lastStoneWeight(self, stones):\n | linfq | NORMAL | 2022-04-07T01:39:27.024715+00:00 | 2022-04-07T08:05:44.013651+00:00 | 1,913 | false | **Please UPVOTE if you LIKE!** \uD83D\uDE01\n\n```\nfrom sortedcontainers import SortedList\n\n\nclass Solution(object):\n def lastStoneWeight(self, stones):\n sl = SortedList(stones)\n while len(sl) >= 2:\n y = sl.pop()\n x = sl.pop()\n if y > x: sl.add(y - x) # Note ... | 16 | 0 | ['Python'] | 5 |
last-stone-weight | Easy C++ Solution using Priority Queue | easy-c-solution-using-priority-queue-by-85wr2 | Create a Priority queue (pq)\n2. as long as size of pq > 1:\n every time pop two elements \n subtract second from first\n* if res of subtractions is non-zero pu | chronoviser | NORMAL | 2020-04-12T07:13:42.690129+00:00 | 2020-04-12T07:13:42.690182+00:00 | 2,179 | false | 1. Create a Priority queue (pq)\n2. as long as size of pq > 1:\n* every time pop two elements \n* subtract second from first\n* if res of subtractions is non-zero push this result back into pq\nCODE:\n```\nint lastStoneWeight(vector<int>& stones) {\n priority_queue<int> pq;\n for(auto i : stones) pq.pus... | 16 | 3 | [] | 4 |
last-stone-weight | Priority Queue | Max Heap | Clean Code | Easy Explaination | | priority-queue-max-heap-clean-code-easy-1jbu7 | Intuition\nIf you reached here it\'s for sure you not able to get to the solution in the first place dont worry I did the same mistake. \n\nJust read the questi | yashagrawal20 | NORMAL | 2023-04-24T00:28:41.165448+00:00 | 2023-04-24T00:28:41.165495+00:00 | 1,291 | false | # Intuition\nIf you reached here it\'s for sure you not able to get to the solution in the first place dont worry I did the same mistake. \n\nJust read the question nicely, It says every time you have to pick the stones with largest weight, so for sure you might have sorted the Array and applied a greedy approach,but y... | 15 | 0 | ['Array', 'Greedy', 'Heap (Priority Queue)', 'C++'] | 3 |
last-stone-weight | Python Solution [4 lines] | python-solution-4-lines-by-shubhamthrill-srdk | \n\nclass Solution:\n def lastStoneWeight(self, stones: List[int]) -> int:\n for i in range(len(stones) - 1):\n stones.sort()\n | shubhamthrills | NORMAL | 2020-04-12T07:21:44.859956+00:00 | 2020-04-13T05:34:39.270630+00:00 | 2,637 | false | ```\n\nclass Solution:\n def lastStoneWeight(self, stones: List[int]) -> int:\n for i in range(len(stones) - 1):\n stones.sort()\n stones.append(stones.pop() - stones.pop()) \n return stones[0]\n\t\t\n\t\t\n\t\tFollow me for more intresting programming questions :\n\t\t\t\t\t\t\th... | 15 | 4 | ['Python'] | 7 |
last-stone-weight | 🔥 [LeetCode The Hard Way] 🔥 Explained Line By Line | leetcode-the-hard-way-explained-line-by-g2afw | We can see that after two stones break we need to replace them back in the array. Where depends on how much they broke down, and it isn\'t always guaranteed to | __wkw__ | NORMAL | 2023-04-24T03:55:37.955063+00:00 | 2023-04-26T15:20:32.267021+00:00 | 1,427 | false | We can see that after two stones break we need to replace them back in the array. Where depends on how much they broke down, and it isn\'t always guaranteed to be the end. This points toward a data structure that allows us to restructure efficiently, and that would be a Max Heap.\n\nA max heap is a tree structure that ... | 14 | 1 | ['Heap (Priority Queue)', 'Python', 'C++'] | 0 |
last-stone-weight | 1046 | JavaScript Recursive One-Liner | 1046-javascript-recursive-one-liner-by-s-gegs | Runtime: 64 ms, faster than 52.83% of JavaScript online submissions\n> Memory Usage: 35.2 MB, less than 100.00% of JavaScript online submissions\n\n\nconst last | sporkyy | NORMAL | 2020-02-03T14:31:14.075293+00:00 | 2022-07-14T13:40:02.593086+00:00 | 1,720 | false | > Runtime: **64 ms**, faster than *52.83%* of JavaScript online submissions\n> Memory Usage: **35.2 MB**, less than *100.00%* of JavaScript online submissions\n\n```\nconst lastStoneWeight = s =>\n 1 === s.length\n ? s[0]\n : lastStoneWeight(s.sort((a, b) => a - b).concat(s.pop() - s.pop()));\n```\n | 14 | 3 | ['Recursion', 'JavaScript'] | 1 |
last-stone-weight | Rust heap and matching | rust-heap-and-matching-by-minamikaze392-q9wu | Code is short thanks to Rust\'s pattern matching:\nrust\nuse std::collections::BinaryHeap;\n\nimpl Solution {\n pub fn last_stone_weight(stones: Vec<i32>) -> | Minamikaze392 | NORMAL | 2022-04-07T04:58:10.259900+00:00 | 2022-04-07T04:58:10.259949+00:00 | 288 | false | Code is short thanks to Rust\'s pattern matching:\n```rust\nuse std::collections::BinaryHeap;\n\nimpl Solution {\n pub fn last_stone_weight(stones: Vec<i32>) -> i32 {\n let mut heap = BinaryHeap::from(stones);\n loop {\n match (heap.pop(), heap.pop()) {\n (Some(a), Some(b)) =>... | 12 | 0 | ['Rust'] | 0 |
last-stone-weight | Python solution. Simplest .2 line | python-solution-simplest-2-line-by-shawn-ynyt | \nclass Solution:\n def lastStoneWeight(self, stones: List[int]) -> int:\n while len(stones) > 1: stones.append(stones.pop(stones.index(max(stones))) | shawnzhangxinyao | NORMAL | 2020-04-12T19:28:55.673817+00:00 | 2020-07-18T07:25:22.046286+00:00 | 1,995 | false | ```\nclass Solution:\n def lastStoneWeight(self, stones: List[int]) -> int:\n while len(stones) > 1: stones.append(stones.pop(stones.index(max(stones))) - stones.pop(stones.index(max(stones))))\n return stones[0]\n```\n\n | 12 | 0 | ['Python', 'Python3'] | 4 |
last-stone-weight | C++ CountSort / BucketSort solution | c-countsort-bucketsort-solution-by-babhi-z2w1 | Since range of the elements is limited to integers between 1 and 1000, we can easily extend a bucket sort / count sort technique to this problem.\n\n1. Keep cou | babhishek21 | NORMAL | 2020-04-12T08:45:31.596382+00:00 | 2020-04-12T08:45:31.596435+00:00 | 1,118 | false | Since range of the elements is limited to integers between 1 and 1000, we can easily extend a bucket sort / count sort technique to this problem.\n\n1. Keep count of elements (in say array `arr`) against the indexes derived from their values. So, if we see a value `x`, we increment `arr[x]`. Thus each index is marking ... | 12 | 2 | [] | 3 |
last-stone-weight | Java | 4 liner | Explained | java-4-liner-explained-by-prashant404-1i79 | Idea:\n Push all stones in a max-heap\n Poll two stones, and push their difference back into the heap\n Do this till there\'s only 1 stone left\n\n>T/S: O(n lg | prashant404 | NORMAL | 2019-08-08T21:08:47.687835+00:00 | 2022-04-07T01:33:15.873909+00:00 | 1,190 | false | **Idea:**\n* Push all stones in a max-heap\n* Poll two stones, and push their difference back into the heap\n* Do this till there\'s only 1 stone left\n\n>**T/S:** O(n lg n)/O(n), where n = size(stones)\n```\npublic int lastStoneWeight(int[] stones) {\n\tvar maxHeap = new PriorityQueue<Integer>(Collections.reverseOrder... | 12 | 0 | ['Heap (Priority Queue)', 'Java'] | 0 |
last-stone-weight | 🔥Easy 🔥Java 🔥Soluton using 🔥PriorityQueue with 🔥Explanation/Intuition | easy-java-soluton-using-priorityqueue-wi-wy71 | PLEASE UPVOTE\n\n\n\n\n# Intuition\n Describe your first thoughts on how to solve this problem. \nUsing Priority Queue to sort at every operation.\n\n# Approach | shahscript | NORMAL | 2023-04-24T01:06:35.165472+00:00 | 2023-04-24T01:06:35.165496+00:00 | 1,931 | false | # PLEASE UPVOTE\n\n\n\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUsing Priority Queue to sort at every operation.\n\n# Approach\n<!-- De... | 11 | 3 | ['Java'] | 0 |
last-stone-weight | Easy JS Solution | easy-js-solution-by-hbjorbj-5p57 | \n/**\n * @param {number[]} stones\n * @return {number}\n */\nvar lastStoneWeight = function(stones) {\n while (stones.length > 1) {\n let max1 = Math | hbjorbj | NORMAL | 2020-07-01T09:17:51.179658+00:00 | 2020-07-01T09:17:51.179699+00:00 | 1,095 | false | ```\n/**\n * @param {number[]} stones\n * @return {number}\n */\nvar lastStoneWeight = function(stones) {\n while (stones.length > 1) {\n let max1 = Math.max(...stones);\n stones.splice(stones.indexOf(max1),1);\n let max2 = Math.max(...stones);\n stones.splice(stones.indexOf(max2),1);\n ... | 11 | 1 | ['JavaScript'] | 3 |
last-stone-weight | O(nlogn) and O(n) algo | onlogn-and-on-algo-by-nits2010-epso | O(n*log(n)) Using Priority Queue\nO(n) bucket sort\n\n# Code\n\n# Approach : Builtin Priorith Queue:\n\n\n/**\n * O(n*log(n))\n * Runtime: 1 ms, faster than 97. | nits2010 | NORMAL | 2019-08-16T17:49:50.294939+00:00 | 2024-08-30T20:54:33.111898+00:00 | 2,485 | false | $$O(n*log(n))$$ Using Priority Queue\n$$O(n)$$ bucket sort\n\n# Code\n\n# Approach : Builtin Priorith Queue:\n```\n\n/**\n * O(n*log(n))\n * Runtime: 1 ms, faster than 97.26% of Java online submissions for Last Stone Weight.\n * Memory Usage: 34.1 MB, less than 100.00% of Java online submissions for Last Stone Weight.\... | 11 | 2 | ['Heap (Priority Queue)', 'Bucket Sort', 'Java'] | 4 |
last-stone-weight | Python3 easy Solution with Explanation || quibler7 | python3-easy-solution-with-explanation-q-dvri | Code\n\nclass Solution:\n def lastStoneWeight(self, stones: List[int]) -> int:\n #first sort the list\n stones.sort()\n\n while stones:\ | quibler7 | NORMAL | 2023-04-24T03:16:03.362593+00:00 | 2023-04-24T03:16:03.362632+00:00 | 4,488 | false | # Code\n```\nclass Solution:\n def lastStoneWeight(self, stones: List[int]) -> int:\n #first sort the list\n stones.sort()\n\n while stones:\n #most heaviest stone\n s1 = stones.pop()\n\n #if list is empty after removing one stone i.e s1 then \n #retur... | 10 | 0 | ['Python3'] | 0 |
last-stone-weight | JS | Heap | Easy Understanding | js-heap-easy-understanding-by-gurubalanh-1ov5 | Solution 1 - O(n^2logn)\n\n\nvar lastStoneWeight = function(stones) {\n\n while(stones.length > 1) {\n stones.sort((a, b) => a - b);\n let x = | gurubalanh | NORMAL | 2022-09-18T16:23:12.945665+00:00 | 2022-09-18T16:23:12.945704+00:00 | 1,188 | false | Solution 1 - O(n^2*logn)\n\n```\nvar lastStoneWeight = function(stones) {\n\n while(stones.length > 1) {\n stones.sort((a, b) => a - b);\n let x = stones.pop();\n let y = stones.pop();\n \n if(x === y) continue;\n else stones.push(Math.abs(x - y));\n }\n \n return s... | 10 | 0 | ['Heap (Priority Queue)', 'JavaScript'] | 0 |
last-stone-weight | Simple solution using ArrayList Java. Self explanatory | simple-solution-using-arraylist-java-sel-f4zh | class Solution {\n\n public int lastStoneWeight(int[] stones) {\n \n ArrayList ar = new ArrayList<>();\n \n for(int i=0;i1){\n | RUPESHYADAV120 | NORMAL | 2022-04-07T04:41:52.555640+00:00 | 2022-04-07T06:27:41.001272+00:00 | 748 | false | class Solution {\n\n public int lastStoneWeight(int[] stones) {\n \n ArrayList<Integer> ar = new ArrayList<>();\n \n for(int i=0;i<stones.length;i++){\n ar.add(stones[i]);\n }\n \n \n \n while(ar.size()>1){\n \n Collections.so... | 10 | 0 | ['Array', 'Java'] | 3 |
last-stone-weight | |Java| Easy and Fast Solution | java-easy-and-fast-solution-by-khalidcod-gesv | \n\n\nclass Solution {\n public int lastStoneWeight(int[] stones) {\n Arrays.sort(stones);\n int count = stones.length-1;\n while(count! | Khalidcodes19 | NORMAL | 2022-04-07T00:22:43.631001+00:00 | 2022-04-07T08:39:52.041638+00:00 | 1,621 | false | \n\n```\nclass Solution {\n public int lastStoneWeight(int[] stones) {\n Arrays.sort(stones);\n int count = stones.length-1;\n while(count!=0)\n {\n if(stones[stones.length-1]==stones[stones.length-2])\n {\n stones[stones.length-1]=0;\n ... | 10 | 1 | ['Java'] | 3 |
last-stone-weight | Go heap solution | go-heap-solution-by-casd82-5f1u | Cause all I do is dance.\n\ntype IntHeap []int\n\nfunc (h IntHeap) Len() int {return len(h)}\nfunc (h IntHeap) Less(i, j int) bool {return h[i] > h[j]}\nfunc (h | casd82 | NORMAL | 2020-08-04T13:02:57.613847+00:00 | 2020-08-04T13:02:57.613895+00:00 | 819 | false | Cause all I do is dance.\n```\ntype IntHeap []int\n\nfunc (h IntHeap) Len() int {return len(h)}\nfunc (h IntHeap) Less(i, j int) bool {return h[i] > h[j]}\nfunc (h IntHeap) Swap(i, j int) {h[i], h[j] = h[j], h[i]}\nfunc (h *IntHeap) Push(x interface{}) {*h = append(*h, x.(int))}\nfunc (h *IntHeap) Pop() interface{} {\n... | 10 | 0 | ['Go'] | 1 |
last-stone-weight | [Rust] Binary Heap | rust-binary-heap-by-kichooo-7bql | \nuse std::collections::BinaryHeap;\n\nimpl Solution {\n pub fn last_stone_weight(stones: Vec<i32>) -> i32 {\n let mut heap = BinaryHeap::from(stones) | kichooo | NORMAL | 2020-01-31T12:20:52.692389+00:00 | 2020-01-31T12:20:52.692423+00:00 | 222 | false | ```\nuse std::collections::BinaryHeap;\n\nimpl Solution {\n pub fn last_stone_weight(stones: Vec<i32>) -> i32 {\n let mut heap = BinaryHeap::from(stones);\n while let Some(stone) = heap.pop() {\n match heap.pop() {\n Some(val) => heap.push(stone - val),\n None... | 10 | 2 | [] | 0 |
last-stone-weight | Easy Python Solution❤ | easy-python-solution-by-meet_10-wo1q | \n\n# Code\n\nclass Solution:\n def lastStoneWeight(self, stones: List[int]) -> int:\n while True:\n stones = sorted(stones,reverse = True) | Meet_10 | NORMAL | 2023-04-24T05:05:14.738963+00:00 | 2023-04-24T05:05:14.739004+00:00 | 1,307 | false | \n\n# Code\n```\nclass Solution:\n def lastStoneWeight(self, stones: List[int]) -> int:\n while True:\n stones = sorted(stones,reverse = True)\n if len(stones) == 1:\n return stones[0]\n elif len(stones) == 0:\n return 0\n first = stone... | 9 | 0 | ['Python3'] | 2 |
last-stone-weight | C++ || 100% || SHORTEST AND EASIEST || Without using any data structure | c-100-shortest-and-easiest-without-using-g5ul | \n\u2714without using priority_queue\n\u2714all you need to do is sorting the array each time you modify it.\nclass Solution {\npublic:\n int lastStoneWeight | rab8it | NORMAL | 2022-04-07T03:05:51.103506+00:00 | 2022-04-07T03:05:51.103542+00:00 | 916 | false | ```\n\u2714without using priority_queue\n\u2714all you need to do is sorting the array each time you modify it.\nclass Solution {\npublic:\n int lastStoneWeight(vector<int>&s) {\n sort(s.begin(),s.end());\n while(s.size()>1){\n int i=s.size()-1;\n int x=s[i],y=s[i-1];\n ... | 9 | 0 | ['Array', 'Sorting'] | 1 |
last-stone-weight | Simple Binary Search based Solution - O(nlogn) | simple-binary-search-based-solution-onlo-wseb | csharp\npublic class Solution {\n public int LastStoneWeight(int[] stones)\n {\n if (stones.Length == 2)\n {\n retu | christris | NORMAL | 2019-05-19T04:13:13.665218+00:00 | 2019-05-19T04:13:13.665398+00:00 | 864 | false | ``` csharp\npublic class Solution {\n public int LastStoneWeight(int[] stones)\n {\n if (stones.Length == 2)\n {\n return Math.Abs(stones[1] - stones[0]);\n }\n\n Array.Sort(stones);\n List<int> s = new List<int>(stones);\n\n while... | 9 | 4 | ['Binary Search'] | 2 |
last-stone-weight | Easy Python Solution | easy-python-solution-by-vistrit-nfq1 | Code\n\nclass Solution:\n def lastStoneWeight(self, stones: List[int]) -> int:\n stones.sort()\n while len(stones)>1:\n y=stones.pop | vistrit | NORMAL | 2023-04-24T12:47:19.471735+00:00 | 2023-04-24T12:47:19.471771+00:00 | 1,297 | false | # Code\n```\nclass Solution:\n def lastStoneWeight(self, stones: List[int]) -> int:\n stones.sort()\n while len(stones)>1:\n y=stones.pop(-1)\n x=stones.pop(-1)\n if x!=y:\n stones.append(y-x)\n stones.sort()\n return stones[0] if len(st... | 8 | 0 | ['Python3'] | 1 |
last-stone-weight | Python Elegant & Short | Max Heap | python-elegant-short-max-heap-by-kyrylo-w132k | Complexity\n- Time complexity: O(n * \log_2 {n})\n- Space complexity: O(n)\n\n# Maximum heap code\n\nclass MaxHeap:\n def __init__(self, data: List[int]):\n | Kyrylo-Ktl | NORMAL | 2023-04-24T07:39:53.926455+00:00 | 2023-04-24T07:39:53.926491+00:00 | 2,531 | false | # Complexity\n- Time complexity: $$O(n * \\log_2 {n})$$\n- Space complexity: $$O(n)$$\n\n# Maximum heap code\n```\nclass MaxHeap:\n def __init__(self, data: List[int]):\n self.data = [-num for num in data]\n heapq.heapify(self.data)\n\n def push(self, item: int):\n heapq.heappush(self.data, -... | 8 | 0 | ['Heap (Priority Queue)', 'Python', 'Python3'] | 1 |
last-stone-weight | Python - Solution using recursion | python-solution-using-recursion-by-cppyg-huth | \nclass Solution:\n def lastStoneWeight(self, nums: List[int]) -> int: \n if not nums:\n return 0\n \n elif len(nums) | cppygod | NORMAL | 2020-04-12T19:25:44.694971+00:00 | 2020-04-12T19:25:57.868110+00:00 | 975 | false | ```\nclass Solution:\n def lastStoneWeight(self, nums: List[int]) -> int: \n if not nums:\n return 0\n \n elif len(nums) == 1:\n return nums[0]\n \n elif len(nums) == 2:\n return abs(nums[0] - nums[1])\n \n else:\n ma... | 8 | 0 | ['Recursion', 'Python', 'Python3'] | 1 |
last-stone-weight | Two Appraoches :Heapq and Sorting | two-appraoches-heapq-and-sorting-by-ganj-zzco | Heap Approach : TC : (NLogN)\n\nclass Solution:\n def lastStoneWeight(self, stones: List[int]) -> int:\n list1=[-x for x in stones]\n while le | GANJINAVEEN | NORMAL | 2023-04-24T09:45:47.816441+00:00 | 2023-04-24T09:45:47.816471+00:00 | 1,201 | false | # Heap Approach : TC : (NLogN)\n```\nclass Solution:\n def lastStoneWeight(self, stones: List[int]) -> int:\n list1=[-x for x in stones]\n while len(list1)>1:\n heapq.heapify(list1)\n a,b=heapq.heappop(list1),heapq.heappop(list1)\n heapq.heappush(list1,-(abs(a-b)))\n ... | 7 | 0 | ['Python'] | 0 |
last-stone-weight | 100% Beats || Easy C++ Solution || Just see for yourself | 100-beats-easy-c-solution-just-see-for-y-lei6 | Intuition\n Describe your first thoughts on how to solve this problem. \nsort in descending order and going through the first two elements and repeating the pro | isundeep0 | NORMAL | 2023-04-24T04:37:49.628558+00:00 | 2023-05-21T16:07:36.036258+00:00 | 2,018 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nsort in descending order and going through the first two elements and repeating the process.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe approach is very simple. Follow the following steps to understand the... | 7 | 0 | ['C++'] | 2 |
last-stone-weight | [Golang] MaxHeap | golang-maxheap-by-vasakris-ut6k | Complexity\n- Time complexity:\nO(NlogN)\n\n- Space complexity:\nO(N)\n\n# Code\n\nfunc lastStoneWeight(stones []int) int {\n maxHeap := &MaxHeap{}\n\n fo | vasakris | NORMAL | 2023-02-15T11:22:14.821527+00:00 | 2023-02-15T11:22:14.821554+00:00 | 773 | false | # Complexity\n- Time complexity:\nO(NlogN)\n\n- Space complexity:\nO(N)\n\n# Code\n```\nfunc lastStoneWeight(stones []int) int {\n maxHeap := &MaxHeap{}\n\n for _, stone := range stones {\n heap.Push(maxHeap, stone)\n }\n\n for maxHeap.Len() > 1 {\n stone1 := heap.Pop(maxHeap).(int)\n s... | 7 | 0 | ['Go'] | 1 |
last-stone-weight | c# PriorityQueue .NET6 | c-priorityqueue-net6-by-yokee06-zej9 | Use c# PriorityQueue\n\n\npublic class Solution {\n public int LastStoneWeight(int[] stones) {\n PriorityQueue<int, int> queue = new();\n forea | yokee06 | NORMAL | 2022-07-21T20:05:01.583485+00:00 | 2022-07-21T20:05:33.713668+00:00 | 334 | false | Use c# PriorityQueue\n\n```\npublic class Solution {\n public int LastStoneWeight(int[] stones) {\n PriorityQueue<int, int> queue = new();\n foreach(int s in stones)\n {\n queue.Enqueue(s,-s);\n }\n while(queue.Count >1)\n {\n int stone1 = queue.Dequeue... | 7 | 0 | ['Heap (Priority Queue)'] | 2 |
last-stone-weight | C# 88% | c-88-by-rudymiked-ee5y | \npublic class Solution {\n public int LastStoneWeight(int[] stones) {\n List<int> stoneList = new List<int>(stones);\n return stoneHelper(ston | rudymiked | NORMAL | 2020-05-30T21:58:10.531853+00:00 | 2020-05-30T21:58:10.531903+00:00 | 295 | false | ```\npublic class Solution {\n public int LastStoneWeight(int[] stones) {\n List<int> stoneList = new List<int>(stones);\n return stoneHelper(stoneList);\n }\n \n public int stoneHelper(List<int> stones) {\n \n if(stones.Count == 0 )\n return 0;\n else if (stone... | 7 | 0 | [] | 0 |
last-stone-weight | JavaScript Priority Queue Solution O(N) | javascript-priority-queue-solution-on-by-y9qc | javascript\n/**\n * @param {number[]} stones\n * @return {number}\n */\nvar lastStoneWeight = function(stones) {\n const heap = new MaxHeap(stones);\n while ( | shengdade | NORMAL | 2020-02-24T03:30:10.574670+00:00 | 2020-02-24T03:30:10.574701+00:00 | 1,678 | false | ```javascript\n/**\n * @param {number[]} stones\n * @return {number}\n */\nvar lastStoneWeight = function(stones) {\n const heap = new MaxHeap(stones);\n while (heap.size() > 1) {\n const max1 = heap.poll();\n const max2 = heap.poll();\n if (max1 > max2) heap.offer(max1 - max2);\n }\n return heap.size() ==... | 7 | 0 | ['JavaScript'] | 3 |
last-stone-weight | C++ vector 100% time and space | c-vector-100-time-and-space-by-codily-fyuj | \nclass Solution {\npublic:\n int lastStoneWeight(vector<int>& stones) {\n while(stones.size() > 1){\n sort(stones.begin(),stones.end(),gre | codily | NORMAL | 2020-01-24T11:30:17.071182+00:00 | 2020-01-24T11:30:38.435438+00:00 | 783 | false | ```\nclass Solution {\npublic:\n int lastStoneWeight(vector<int>& stones) {\n while(stones.size() > 1){\n sort(stones.begin(),stones.end(),greater<int>());\n if(stones[0] == stones[1])\n stones.erase(stones.begin(),stones.begin()+2);\n else{\n sto... | 7 | 1 | ['C', 'C++'] | 3 |
last-stone-weight | Javascript | javascript-by-fs2329-8e09 | \n/**\n * @param {number[]} stones\n * @return {number}\n */\nvar lastStoneWeight = function(stones) {\n if(stones.length < 2) return stones;\n while(ston | fs2329 | NORMAL | 2019-12-30T01:54:48.828211+00:00 | 2019-12-30T01:54:48.828313+00:00 | 556 | false | ```\n/**\n * @param {number[]} stones\n * @return {number}\n */\nvar lastStoneWeight = function(stones) {\n if(stones.length < 2) return stones;\n while(stones.length > 1){\n let index1 = stones.indexOf(Math.max(...stones));\n let stone1 = stones.splice(index1,1);\n let index2 = stones.indexO... | 7 | 2 | [] | 4 |
last-stone-weight | Java Solution using PriorityQueue | java-solution-using-priorityqueue-by-mak-03dw | Store all elements in the Priority Queue in decreasing order.\n Each time, poll 2 elements from the Priority Queue until its size is 1 and add the absolute diff | makubex74 | NORMAL | 2019-05-19T07:19:16.297388+00:00 | 2019-05-19T07:19:16.297460+00:00 | 431 | false | * Store all elements in the Priority Queue in decreasing order.\n* Each time, poll 2 elements from the Priority Queue until its size is 1 and add the absolute difference between the 2 elements back to the queue.\n* Return 0 if the PriorityQueue is empty or return the last element remaining in the PriorityQueue\n```\npu... | 7 | 2 | [] | 0 |
last-stone-weight | Java || Don't worry My Solution is Best || 100% || 92% || 39,6 MB | java-dont-worry-my-solution-is-best-100-n9stk | \t* class Solution {\n\t\t\tpublic int lastStoneWeight(int[] stones) {\n\t\t\t\tArrayList list = new ArrayList<>();\n\t\t\t\tfor (int a : stones) {\n\t\t\t\t | sardor_user | NORMAL | 2023-01-11T16:44:45.933918+00:00 | 2023-07-21T09:16:15.963645+00:00 | 46 | false | \t* class Solution {\n\t\t\tpublic int lastStoneWeight(int[] stones) {\n\t\t\t\tArrayList<Integer> list = new ArrayList<>();\n\t\t\t\tfor (int a : stones) {\n\t\t\t\t\tlist.add(a);\n\t\t\t\t}\n\t\t\t\tCollections.sort(list);\n\t\t\t\twhile (list.size() > 1) {\n\t\t\t\t\tint a = list.size();\n\t\t\t\t\tif (list.get(a... | 6 | 0 | ['Array', 'Java'] | 0 |
last-stone-weight | [Java] Runtime: 1ms, faster than 99.49% || Queue and Iterative Solutions | java-runtime-1ms-faster-than-9949-queue-8miuf | PriorityQueue solution:\n\nclass Solution {\n public int lastStoneWeight(int[] stones) {\n Queue<Integer> queue = new PriorityQueue<>(Collections.reve | decentos | NORMAL | 2022-11-18T03:47:39.208820+00:00 | 2022-11-18T03:47:39.208872+00:00 | 1,159 | false | PriorityQueue solution:\n```\nclass Solution {\n public int lastStoneWeight(int[] stones) {\n Queue<Integer> queue = new PriorityQueue<>(Collections.reverseOrder());\n for (int i : stones) queue.offer(i);\n\n while (queue.size() > 1) {\n int first = queue.poll();\n int next... | 6 | 0 | ['Java'] | 1 |
last-stone-weight | C++ easy Priority queue solution || 100% time | c-easy-priority-queue-solution-100-time-1k4ip | \nint lastStoneWeight(vector<int>& stones) {\n\n\tpriority_queue<int>pq;\n\tfor(auto x: stones)\n\t{\n\t\tpq.push(x);\n\t}\n\n\twhile(!p.empty())\n\t{\n\t\tint | rajsaurabh | NORMAL | 2021-11-26T05:23:48.192395+00:00 | 2021-11-26T05:27:09.445947+00:00 | 622 | false | ```\nint lastStoneWeight(vector<int>& stones) {\n\n\tpriority_queue<int>pq;\n\tfor(auto x: stones)\n\t{\n\t\tpq.push(x);\n\t}\n\n\twhile(!p.empty())\n\t{\n\t\tint y = pq.top();\n\t\tif(pq.size()==1)return y;\n\t\tpq.pop();\n\t\tint rem = abs(y - pq.top());\n\t\tpq.pop();\n\t\tpq.push(rem);\n\n }\n return ... | 6 | 0 | ['C', 'Heap (Priority Queue)', 'C++'] | 4 |
last-stone-weight | Rust solution | rust-solution-by-bigmih-jopx | \nimpl Solution {\n pub fn last_stone_weight(stones: Vec<i32>) -> i32 {\n use std::collections::BinaryHeap;\n\n let mut h = BinaryHeap::from(st | BigMih | NORMAL | 2021-10-16T19:12:25.279186+00:00 | 2021-10-16T19:14:34.723943+00:00 | 222 | false | ```\nimpl Solution {\n pub fn last_stone_weight(stones: Vec<i32>) -> i32 {\n use std::collections::BinaryHeap;\n\n let mut h = BinaryHeap::from(stones);\n while h.len() > 1 {\n let s1 = h.pop().unwrap();\n let s2 = h.pop().unwrap();\n h.push(s1 - s2)\n }\n... | 6 | 0 | ['Rust'] | 0 |
last-stone-weight | python heapq | python-heapq-by-dpark068-19wl | \n"""\nChoose two heaviest stones and smash them together\n\nx==y: destroyed\nx != y, new weight is difference, return weight of stome\n\nApproach:\nuse max hea | dpark068 | NORMAL | 2020-09-06T19:24:41.566306+00:00 | 2020-09-06T19:24:41.566368+00:00 | 670 | false | ```\n"""\nChoose two heaviest stones and smash them together\n\nx==y: destroyed\nx != y, new weight is difference, return weight of stome\n\nApproach:\nuse max heap, get difference\n"""\nimport heapq\n\nclass Solution:\n def lastStoneWeight(self, stones: List[int]) -> int:\n stones = [-x for x in stones]\n ... | 6 | 0 | ['Heap (Priority Queue)', 'Python', 'Python3'] | 0 |
last-stone-weight | C++ Solution With Explanation | c-solution-with-explanation-by-monga_anm-ujd1 | Priority Queue Implementation\n Make a priority queue(binary max heap) which automatically arrange the element in sorted order.\n Then pick the first element ( | monga_anmol123 | NORMAL | 2020-04-12T07:26:16.547828+00:00 | 2020-04-12T07:26:16.547886+00:00 | 1,525 | false | **Priority Queue Implementation**\n* Make a priority queue(binary max heap) which automatically arrange the element in sorted order.\n* Then pick the first element (which is maximum) and 2nd element(2nd max) , if both are equal we dont have to push anything , if not equal push difference of both in queue.\n* Do the a... | 6 | 1 | ['C', 'Heap (Priority Queue)', 'C++'] | 2 |
last-stone-weight | Intuitive C++ solution. 100% run time, 100% memory. | intuitive-c-solution-100-run-time-100-me-4cli | ```class Solution {\npublic:\n int lastStoneWeight(vector& stones) { \n while(stones.size() > 1)\n {\n sort(stones.begin(),st | coolbassist | NORMAL | 2019-05-27T12:01:09.116282+00:00 | 2019-05-27T12:01:25.200496+00:00 | 1,091 | false | ```class Solution {\npublic:\n int lastStoneWeight(vector<int>& stones) { \n while(stones.size() > 1)\n {\n sort(stones.begin(),stones.end());\n int y = stones[stones.size()-1];\n int x = stones[stones.size()-2];\n \n if(x == y)\n ... | 6 | 2 | [] | 2 |
last-stone-weight | Java Simplest Easiest Priority Queue | java-simplest-easiest-priority-queue-by-oznoy | \nclass Solution {\n public int lastStoneWeight(int[] stones) {\n PriorityQueue<Integer> queue = new PriorityQueue<Integer>(Collections.reverseOrder() | Ordinary-Coder | NORMAL | 2019-05-19T04:44:49.401451+00:00 | 2023-03-08T21:25:33.025788+00:00 | 924 | false | ```\nclass Solution {\n public int lastStoneWeight(int[] stones) {\n PriorityQueue<Integer> queue = new PriorityQueue<Integer>(Collections.reverseOrder());\n for (int s : stones) {\n queue.add(s);\n }\n while (queue.size() > 1) {\n int weight1 = queue.poll();\n ... | 6 | 3 | ['Java'] | 2 |
last-stone-weight | Hank Schrader's Rock Collection | heap-solution-no-bull-by-qimprch6bn-l4mb | IntuitionYo, dude, like, okay—so we gotta smash the biggest rocks first, right? But how the heck do we always grab the heaviest ones without checkin’ the whole | QIMPRCh6bN | NORMAL | 2025-01-30T22:05:15.006438+00:00 | 2025-02-20T17:55:39.985139+00:00 | 167 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Yo, dude, like, okay—so we gotta smash the biggest rocks first, right? But how the heck do we always grab the heaviest ones without checkin’ the whole list every time? Oh snap, a max-heap! But wait, Python’s like, “Nah, bro, I only got min-... | 5 | 0 | ['Heap (Priority Queue)', 'Python3'] | 1 |
last-stone-weight | C# simple solution with PriorityQueue | c-simple-solution-with-priorityqueue-by-pu1d4 | Code\n\npublic class Solution {\n public int LastStoneWeight(int[] stones) {\n\n var heap = new PriorityQueue<int, int>();\n \n foreach | evkobak | NORMAL | 2023-04-17T02:03:18.949041+00:00 | 2023-04-17T02:33:56.755450+00:00 | 540 | false | # Code\n```\npublic class Solution {\n public int LastStoneWeight(int[] stones) {\n\n var heap = new PriorityQueue<int, int>();\n \n foreach (var stone in stones)\n heap.Enqueue(stone, 0 - stone);\n\n while (heap.Count > 1)\n {\n var newStone = heap.Dequeue() ... | 5 | 0 | ['C#'] | 0 |
last-stone-weight | Kotlin: Priority Queue | kotlin-priority-queue-by-artemasoyan-w3uw | Code\n\nclass Solution {\n fun lastStoneWeight(stones: IntArray): Int {\n val h = PriorityQueue<Int> { a, b -> b.compareTo(a) }\n stones.forEac | artemasoyan | NORMAL | 2022-12-13T15:29:24.345995+00:00 | 2022-12-13T15:29:24.346028+00:00 | 182 | false | # Code\n```\nclass Solution {\n fun lastStoneWeight(stones: IntArray): Int {\n val h = PriorityQueue<Int> { a, b -> b.compareTo(a) }\n stones.forEach { h.add(it) }\n\n while (h.size > 1) { \n h.add(h.poll() - h.poll())\n }\n \n return h.poll()\n }\n}\n``` | 5 | 0 | ['Heap (Priority Queue)', 'Kotlin'] | 0 |
last-stone-weight | ✅C++ ||EASY && SHORT|| Faster than 100% || Priority_queue | c-easy-short-faster-than-100-priority_qu-wpsm | \n\nT->O(n) && S->O(n)\n\n\tclass Solution {\n\t\tpublic:\n\t\t\tint lastStoneWeight(vector& st) {\n\t\t\t\tint n=st.size();\n\t\t\t\tpriority_queueq;\n\t\t\t\t | abhinav_0107 | NORMAL | 2022-10-02T07:35:49.814847+00:00 | 2022-10-02T07:35:49.814880+00:00 | 1,794 | false | \n\n**T->O(n) && S->O(n)**\n\n\tclass Solution {\n\t\tpublic:\n\t\t\tint lastStoneWeight(vector<int>& st) {\n\t\t\t\tint n=st.size();\n\t\t\t\tpriority_queue<int>q;\n\t\t\t\tfor(auto i: st) q.push(i);\n\t\t\t\t... | 5 | 0 | ['C', 'Heap (Priority Queue)', 'C++'] | 0 |
last-stone-weight | C++ naive solution | c-naive-solution-by-raunak_01-szz5 | \nint lastStoneWeight(vector<int>& stones) {\n sort(stones.begin(),stones.end());\n int a=stones.size()-1;\n if(a==0){\n return | Raunak_01 | NORMAL | 2022-04-07T11:46:30.636087+00:00 | 2022-04-07T11:46:30.636119+00:00 | 132 | false | ```\nint lastStoneWeight(vector<int>& stones) {\n sort(stones.begin(),stones.end());\n int a=stones.size()-1;\n if(a==0){\n return stones[a];\n }\n for(int i=0;i<stones.size();i++){\n sort(stones.begin(),stones.end());\n if(stones[a]>0 && stones[a-1]>0... | 5 | 0 | [] | 1 |
last-stone-weight | Java Priority Queue | java-priority-queue-by-fllght-i8tj | \npublic int lastStoneWeight(int[] stones) {\n PriorityQueue<Integer> queue = new PriorityQueue<>(Comparator.reverseOrder());\n for (int stone : s | FLlGHT | NORMAL | 2022-04-07T07:21:23.643849+00:00 | 2022-04-07T07:21:23.643893+00:00 | 207 | false | ```\npublic int lastStoneWeight(int[] stones) {\n PriorityQueue<Integer> queue = new PriorityQueue<>(Comparator.reverseOrder());\n for (int stone : stones) {\n queue.offer(stone);\n }\n\n while (queue.size() > 1) {\n queue.offer(queue.poll() - queue.poll());\n }\... | 5 | 0 | ['Java'] | 0 |
last-stone-weight | very easy code with explanation | very-easy-code-with-explanation-by-mamta-mie2 | step 1 create a priority queue\nstep 2 Put all elements into a priority queue.\nstep 3 take two bigest element \npush the difference into queue until\ntwo more | Mamtachahal | NORMAL | 2022-04-07T00:54:04.014773+00:00 | 2022-04-07T01:09:00.689752+00:00 | 281 | false | **step 1 create a priority queue\nstep 2 Put all elements into a priority queue.\nstep 3 take two bigest element \npush the difference into queue until\ntwo more element left.**\n\n**Complexity\nTime O(NlogN)\nSpace O(N)**\n\n\n\n\n```\nclass Solution {\npublic:\n int lastStoneWeight(vector<int>& nums) {\n pr... | 5 | 0 | [] | 0 |
last-stone-weight | Last Stone Weight || Python || Easy || 48 ms | last-stone-weight-python-easy-48-ms-by-w-c11z | \nclass Solution:\n def lastStoneWeight(self, stones: List[int]) -> int:\n while(len(stones)>1):\n p = max(stones)\n pi= stones. | workingpayload | NORMAL | 2022-04-07T00:52:24.142939+00:00 | 2022-04-07T00:52:24.142972+00:00 | 153 | false | ```\nclass Solution:\n def lastStoneWeight(self, stones: List[int]) -> int:\n while(len(stones)>1):\n p = max(stones)\n pi= stones.index(p)\n stones.pop(pi)\n q = max(stones)\n qi = stones.index(q)\n stones.pop(qi)\n stones.append(p-... | 5 | 0 | ['Python'] | 0 |
last-stone-weight | Java Easy Solution | o(nlogn) Time Complexity | Priority Queue | java-easy-solution-onlogn-time-complexit-6ego | The efficient way to retrieve the max from array is to use a max heap, which in Java is a PriorityQueue (min heap) with a reverse comparator.\n\n Follow 4 Easy | sparkle_30 | NORMAL | 2021-08-02T13:25:35.014740+00:00 | 2021-08-02T13:25:35.014783+00:00 | 449 | false | The efficient way to retrieve the max from array is to use a max heap, which in Java is a PriorityQueue (min heap) with a reverse comparator.\n\n Follow 4 Easy steps-\n**Step1** : Create a max priority queue.\n**Step2** : Add all the elements to queue.\n**Step3** : Remove two max element at a time, find the difference ... | 5 | 0 | [] | 1 |
last-stone-weight | Javascript 99% time | javascript-99-time-by-warkanlock-wg9z | It\'s not optimal but it\'s efficient without using a priority queue. Just array manipulation \n\n```/*\n * @param {number[]} stones\n * @return {number}\n /\nv | warkanlock | NORMAL | 2020-04-23T22:50:49.406672+00:00 | 2020-04-23T22:51:02.124500+00:00 | 298 | false | It\'s not optimal but it\'s efficient without using a priority queue. Just array manipulation \n\n```/**\n * @param {number[]} stones\n * @return {number}\n */\nvar lastStoneWeight = function(stones) {\n let size = stones.length;\n \n while(size >= 2){\n stones.sort((a,b)=> { return a-b })\n \n ... | 5 | 0 | [] | 1 |
last-stone-weight | Golang using container/heap | golang-using-containerheap-by-ylz-at-byes | \npackage main\n\nimport (\n\t"container/heap"\n)\n\nfunc lastStoneWeight(stones []int) int {\n\tpq := IntHeap(stones)\n\theap.Init(&pq)\n\tfor pq.Len() > 1 {\n | ylz-at | NORMAL | 2020-03-24T08:10:14.258364+00:00 | 2020-03-24T08:10:14.258400+00:00 | 1,305 | false | ```\npackage main\n\nimport (\n\t"container/heap"\n)\n\nfunc lastStoneWeight(stones []int) int {\n\tpq := IntHeap(stones)\n\theap.Init(&pq)\n\tfor pq.Len() > 1 {\n\t\theap.Push(&pq, heap.Pop(&pq).(int)-heap.Pop(&pq).(int))\n\n\t}\n\treturn heap.Pop(&pq).(int)\n}\n\ntype IntHeap []int\n\nfunc (h IntHeap) Len() int ... | 5 | 0 | ['Heap (Priority Queue)', 'Go'] | 4 |
last-stone-weight | python very simple solution 95% fast | python-very-simple-solution-95-fast-by-g-h6lp | ```\nclass Solution(object):\n def lastStoneWeight(self, stones):\n """\n :type stones: List[int]\n :rtype: int\n """\n \n | gyohogo | NORMAL | 2020-01-01T23:27:08.315532+00:00 | 2020-01-01T23:29:09.264974+00:00 | 603 | false | ```\nclass Solution(object):\n def lastStoneWeight(self, stones):\n """\n :type stones: List[int]\n :rtype: int\n """\n \n while len(stones) > 1:\n stones.sort()\n x, y = stones[-2], stones[-1]\n stones = stones[:-2]\n \n if ... | 5 | 0 | ['Python'] | 1 |
last-stone-weight | [Java] easy solution | java-easy-solution-by-olsh-mrfl | \nclass Solution {\n public int lastStoneWeight(int[] stones) {\n PriorityQueue<Integer>queue = new PriorityQueue<>(Comparator.reverseOrder());\n | olsh | NORMAL | 2019-12-30T21:43:28.339785+00:00 | 2019-12-30T21:43:28.339832+00:00 | 394 | false | ```\nclass Solution {\n public int lastStoneWeight(int[] stones) {\n PriorityQueue<Integer>queue = new PriorityQueue<>(Comparator.reverseOrder());\n for (int item : stones)queue.add(item);\n while (queue.size()>1){\n int i1 = queue.poll();\n int i2 = queue.poll();\n ... | 5 | 2 | ['Java'] | 1 |
last-stone-weight | Python Simple Solution | python-simple-solution-by-saffi-1o7d | \tclass Solution:\n\t\tdef lastStoneWeight(self, stones: List[int]) -> int:\n\t\t\tstones.sort()\n\t\t\twhile len(stones)>1:\n\t\t\t\tt = stones.pop()\n\t\t\t\t | saffi | NORMAL | 2019-11-25T17:25:08.246373+00:00 | 2019-11-25T17:25:21.836780+00:00 | 532 | false | \tclass Solution:\n\t\tdef lastStoneWeight(self, stones: List[int]) -> int:\n\t\t\tstones.sort()\n\t\t\twhile len(stones)>1:\n\t\t\t\tt = stones.pop()\n\t\t\t\tu = stones.pop()\n\t\t\t\tif t==u:\n\t\t\t\t\tcontinue\n\t\t\t\telse:\n\t\t\t\t\tstones.append(t-u)\n\t\t\t\t\tstones.sort()\n\t\t\treturn stones[0] if stones e... | 5 | 0 | ['Python', 'Python3'] | 0 |
last-stone-weight | Javascript simple O(nlogn) solution | javascript-simple-onlogn-solution-by-dav-th9t | \nvar lastStoneWeight = function(stones) {\n if(!stones || stones.length == 0) return 0\n \n while(stones.length > 1) {\n stones.sort((a, b) => | davidhiggins1712 | NORMAL | 2019-05-23T07:25:00.389314+00:00 | 2019-05-23T07:25:00.389380+00:00 | 749 | false | ```\nvar lastStoneWeight = function(stones) {\n if(!stones || stones.length == 0) return 0\n \n while(stones.length > 1) {\n stones.sort((a, b) => b - a)\n let x = stones.shift() - stones.shift()\n stones.push(x)\n }\n \n return stones[0]\n};\n``` | 5 | 3 | ['Sorting', 'JavaScript'] | 2 |
last-stone-weight | C++ 0ms faster than 100% (using priority_queue) | c-0ms-faster-than-100-using-priority_que-jd14 | \nclass Solution {\npublic:\n int lastStoneWeight(vector<int>& stones) {\n priority_queue<int> qu(stones.begin(),stones.end());\n \n whi | liut2016 | NORMAL | 2019-05-22T09:35:57.736100+00:00 | 2019-05-22T09:35:57.736142+00:00 | 702 | false | ```\nclass Solution {\npublic:\n int lastStoneWeight(vector<int>& stones) {\n priority_queue<int> qu(stones.begin(),stones.end());\n \n while(qu.size() != 0 && qu.size() != 1){\n int temp1 = qu.top();\n qu.pop();\n int temp2 = qu.top();\n qu.pop();\n ... | 5 | 2 | [] | 2 |
last-stone-weight | Simple C++ 100/100 | simple-c-100100-by-rathnavels-1f5j | \nclass Solution {\npublic:\n int lastStoneWeight(vector<int>& stones) \n {\n for(int i=stones.size()-1; i>=1;)\n { \n sort(stone | rathnavels | NORMAL | 2019-05-19T20:40:46.012135+00:00 | 2019-05-19T20:44:40.312458+00:00 | 262 | false | ```\nclass Solution {\npublic:\n int lastStoneWeight(vector<int>& stones) \n {\n for(int i=stones.size()-1; i>=1;)\n { \n sort(stones.begin(),stones.end());\n \n auto iNum = stones[i];\n auto iM1Num = stones[i-1];\n auto temp ... | 5 | 2 | [] | 0 |
last-stone-weight | learn heap(max) | learn-heapmax-by-izer-v73u | Intuition\n Describe your first thoughts on how to solve this problem. \nconcept maching with heap:\n\n# Approach\n Describe your approach to solving the proble | izer | NORMAL | 2024-10-13T06:11:45.715531+00:00 | 2024-10-13T06:11:45.715561+00:00 | 71 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nconcept maching with heap:\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nfirst, find max and second max\nif same then pop both else change larger elem as diff.\nat the end print ele. remaining on heap\n\n\n# Comp... | 4 | 0 | ['C++'] | 0 |
last-stone-weight | Better than 100% in runtime. Simple C++ approach | better-than-100-in-runtime-simple-c-appr-k2s8 | Approach\nAlright, in this I am using Priority Queue. In this first I am adding all elements of the vector "stones" in the priority queue called "pq". Now I am | green_day | NORMAL | 2023-04-24T08:19:36.285684+00:00 | 2023-04-24T08:19:36.285725+00:00 | 1,644 | false | # Approach\nAlright, in this I am using Priority Queue. In this first I am adding all elements of the vector "stones" in the priority queue called "pq". Now I am initializing a while loop, setting the condition that, the size of "pq" must be greater than 1. I am simply checking the top 2 elements and doing the required... | 4 | 0 | ['Array', 'Heap (Priority Queue)', 'C++'] | 3 |
last-stone-weight | ✅Java Easy Solution|lBeginner Friendly🔥 | java-easy-solutionlbeginner-friendly-by-83lb9 | Code\n\nclass Solution {\n public int lastStoneWeight(int[] stones) {\n //creating a heap to store elements in descending order\n PriorityQueue | deepVashisth | NORMAL | 2023-04-24T06:45:36.307519+00:00 | 2023-04-24T06:45:36.307559+00:00 | 880 | false | # Code\n```\nclass Solution {\n public int lastStoneWeight(int[] stones) {\n //creating a heap to store elements in descending order\n PriorityQueue<Integer> q = new PriorityQueue<>(Comparator.reverseOrder());\n for(int i = 0 ; i < stones.length; i ++){\n q.add(stones[i]);\n }\... | 4 | 0 | ['Heap (Priority Queue)', 'Java'] | 2 |
last-stone-weight | Ex-Amazon explains a solution with a video, Python, JavaScript, Java and C++ | ex-amazon-explains-a-solution-with-a-vid-t8oy | My youtube channel - KeetCode(Ex-Amazon)\nI create 155 videos for leetcode questions as of April 24, 2023. I believe my channel helps you prepare for the coming | niits | NORMAL | 2023-04-24T03:02:26.129374+00:00 | 2023-04-24T03:02:26.129416+00:00 | 1,496 | false | # My youtube channel - KeetCode(Ex-Amazon)\nI create 155 videos for leetcode questions as of April 24, 2023. I believe my channel helps you prepare for the coming technical interviews. Please subscribe my channel!\n\n### Please subscribe my channel - KeetCode(Ex-Amazon) from here.\n\n**I created a video for this questi... | 4 | 0 | ['C++', 'Java', 'Python3', 'JavaScript'] | 1 |
last-stone-weight | Typescript || Array || Heap | typescript-array-heap-by-webdot-0d9x | Approach\n Describe your approach to solving the problem. \nWe initialize a maximum priority queue which ensures the element we call each time has the maximum w | webdot | NORMAL | 2023-04-24T01:24:15.993361+00:00 | 2023-04-24T01:24:15.993395+00:00 | 454 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nWe initialize a maximum priority queue which ensures the element we call each time has the maximum weight. \n\nWe then insert all stones into this queue. As far as we have at least 2 stones, we pop out the two stones, if they are equal in weight we do... | 4 | 0 | ['Array', 'Heap (Priority Queue)', 'TypeScript'] | 1 |
last-stone-weight | ✅ Easy Java solution || using maxHeap 🏆 || Beginner Friendly 🔥 | easy-java-solution-using-maxheap-beginne-naj7 | Intuition\nNeed to maitain a DS to get top-2 stone, PriorityQueue is best for this\n\n# Approach\n1. Push all elments in prioriyQueue as MaxHeap.\n2. Pick top 2 | yshrini | NORMAL | 2023-04-24T00:16:25.382547+00:00 | 2023-04-24T00:16:25.382583+00:00 | 861 | false | # Intuition\nNeed to maitain a DS to get top-2 stone, PriorityQueue is best for this\n\n# Approach\n1. Push all elments in prioriyQueue as MaxHeap.\n2. Pick top 2 elements form maxHeap, if there is only one element left then that is answer.\n3. If both element are same, no action needed and continue the process.\n4. If... | 4 | 0 | ['Heap (Priority Queue)', 'Java'] | 1 |
last-stone-weight | 🗓️ Daily LeetCoding Challenge April, Day 24 | daily-leetcoding-challenge-april-day-24-qd1r8 | This problem is the Daily LeetCoding Challenge for April, Day 24. Feel free to share anything related to this problem here! You can ask questions, discuss what | leetcode | OFFICIAL | 2023-04-24T00:00:20.445404+00:00 | 2023-04-24T00:00:20.445495+00:00 | 4,213 | false | This problem is the Daily LeetCoding Challenge for April, Day 24.
Feel free to share anything related to this problem here!
You can ask questions, discuss what you've learned from this problem, or show off how many days of streak you've made!
---
If you'd like to share a detailed solution to the problem, please cre... | 4 | 0 | [] | 16 |
last-stone-weight | Java. Heap. Fight of the stones | java-heap-fight-of-the-stones-by-red_pla-in5n | \n\nclass Heap\n{\n int [] heap;\n int size;\n Heap(int[] stones)\n {\n heap = new int[stones.length];\n size = 0;\n for (int i | red_planet | NORMAL | 2023-04-03T16:59:53.734665+00:00 | 2023-04-03T16:59:53.734710+00:00 | 817 | false | \n```\nclass Heap\n{\n int [] heap;\n int size;\n Heap(int[] stones)\n {\n heap = new int[stones.length];\n size = 0;\n for (int i = 0; i < stones.length; i++)\n addStone(stones[i]);\n }\n public int removeMax() //size--\n {\n int answ = heap[0];\n if (... | 4 | 0 | ['Java'] | 2 |
last-stone-weight | Using Heap- 1ms | JAVA ✅ | beat 💯 | using-heap-1ms-java-beat-by-sourabh-jadh-xopo | \n# Complexity\n- Time complexity:\nO(log n)\n\n# Code\n\nclass Solution {\n public int lastStoneWeight(int[] stones) {\n PriorityQueue<Integer> pq=ne | sourabh-jadhav | NORMAL | 2023-02-24T09:13:29.977972+00:00 | 2023-02-24T09:13:29.978023+00:00 | 302 | false | \n# Complexity\n- Time complexity:\nO(log n)\n\n# Code\n```\nclass Solution {\n public int lastStoneWeight(int[] stones) {\n PriorityQueue<Integer> pq=new PriorityQueue<>(Collections.reverseOrder());\n for(int i:stones)\n pq.add(i);\n\n int x;\n int y;\n\n while(pq.size(... | 4 | 0 | ['Array', 'Queue', 'Heap (Priority Queue)', 'Java'] | 0 |
last-stone-weight | Simple solution on Swift / Beats 100% | simple-solution-on-swift-beats-100-by-bl-gp1e | Please upvote if the solution was useful!\n\nfunc lastStoneWeight(_ stones: [Int]) -> Int {\n var stones = stones.sorted(by: >)\n while stones.count != 1 | blackbirdNG | NORMAL | 2023-01-13T13:26:16.269697+00:00 | 2023-01-13T13:26:16.269735+00:00 | 410 | false | ### Please upvote if the solution was useful!\n```\nfunc lastStoneWeight(_ stones: [Int]) -> Int {\n var stones = stones.sorted(by: >)\n while stones.count != 1 {\n let secondItem = stones.remove(at: 1)\n stones[0] -= secondItem\n stones = stones.sorted(by: >)\n }\n return stones[0]\n}\... | 4 | 0 | ['Swift'] | 3 |
last-stone-weight | python, heapq (min) with negative values (equivalent to heap max) | python-heapq-min-with-negative-values-eq-ofu7 | ERROR: type should be string, got "https://leetcode.com/submissions/detail/875123729/ \\nRuntime: 29 ms, faster than 94.25% of Python3 online submissions for Last Stone Weight. \\nMemory Usage: 1" | nov05 | NORMAL | 2023-01-10T02:13:28.407525+00:00 | 2023-01-10T02:14:48.841749+00:00 | 1,375 | false | ERROR: type should be string, got "https://leetcode.com/submissions/detail/875123729/ \\nRuntime: **29 ms**, faster than 94.25% of Python3 online submissions for Last Stone Weight. \\nMemory Usage: 13.8 MB, less than 61.08% of Python3 online submissions for Last Stone Weight. \\n```\\nclass Solution:\\n def lastStoneWeight(self, stones: List[int]) -> int:\\n s = [-s for s in stones]\\n heapify(s)\\n while len(s)>1:\\n heapq.heappush(s, -abs(heappop(s) - heappop(s)))\\n return -s[0]\\n```" | 4 | 0 | ['Heap (Priority Queue)', 'Python', 'Python3'] | 1 |
last-stone-weight | JavaScript using MaxPriorityQueue | javascript-using-maxpriorityqueue-by-yup-c9kn | Finally, there\'s a Max/MinPriorityQueue for JavaScript!\n\nadd -> enqueue( )\nremove -> dequeue( )\nhighest number (peek) -> front( )\n.element -> actual value | yupdduk | NORMAL | 2022-06-19T03:14:31.384139+00:00 | 2022-06-19T03:14:31.384186+00:00 | 560 | false | Finally, there\'s a Max/MinPriorityQueue for JavaScript!\n\nadd -> enqueue( )\nremove -> dequeue( )\nhighest number (peek) -> front( )\n.element -> actual value\n\n```\nvar lastStoneWeight = function(stones) {\n const m = new MaxPriorityQueue()\n for(const w of stones) m.enqueue(w)\n \n while(m.size() > 1){... | 4 | 0 | ['JavaScript'] | 3 |
last-stone-weight | C++ solution with image explanation | No extra space | c-solution-with-image-explanation-no-ext-5dwo | \n\n\nclass Solution {\npublic:\n int lastStoneWeight(vector<int>& stones) {\n while(stones.size() > 1) {\n sort(stones.begin(), stones.end | Progra_marauder | NORMAL | 2022-04-07T12:21:38.108364+00:00 | 2022-04-07T12:22:18.529631+00:00 | 179 | false | \n\n```\nclass Solution {\npublic:\n int lastStoneWeight(vector<int>& stones) {\n while(stones.size() > 1) {\n sort(stones.begin(), stones.end());\n int n = stones.size();\n ... | 4 | 0 | [] | 1 |
last-stone-weight | [ Python ] ✅✅ Simple Python Solution Using Three Approach 🥳✌👍 | python-simple-python-solution-using-thre-d5z6 | If You like the Solution, Don\'t Forget To UpVote Me, Please UpVote! \uD83D\uDD3C\uD83D\uDE4F\n# Apporach 1 Using Priority Queue :-\n# Runtime: 39 ms, faster th | ashok_kumar_meghvanshi | NORMAL | 2022-04-07T10:25:02.699874+00:00 | 2023-04-24T07:20:51.484202+00:00 | 579 | false | # If You like the Solution, Don\'t Forget To UpVote Me, Please UpVote! \uD83D\uDD3C\uD83D\uDE4F\n# Apporach 1 Using Priority Queue :-\n# Runtime: 39 ms, faster than 55.89% of Python3 online submissions for Last Stone Weight.\n# Memory Usage: 14.1 MB, less than 13.28% of Python3 online submissions for Last Stone Weight.... | 4 | 0 | ['Sorting', 'Heap (Priority Queue)', 'Python', 'Python3'] | 0 |
last-stone-weight | simplest c++ solution with comments | simplest-c-solution-with-comments-by-abh-s1jv | \nclass Solution {\npublic:\n int lastStoneWeight(vector<int>& stones) {\n priority_queue<int> pq; //create max heap having maximum element at top\n | abhijeetnishal | NORMAL | 2022-04-07T09:16:49.948500+00:00 | 2022-04-07T09:17:38.567275+00:00 | 36 | false | ```\nclass Solution {\npublic:\n int lastStoneWeight(vector<int>& stones) {\n priority_queue<int> pq; //create max heap having maximum element at top\n for(int x:stones) //insert all elements into priority queue \n pq.push(x);\n while(pq.size()>1){ //iterate unti... | 4 | 0 | ['Heap (Priority Queue)'] | 0 |
nearest-exit-from-entrance-in-maze | An analysis on Time Limit Exceeded (TLE) | an-analysis-on-time-limit-exceeded-tle-b-rn4q | If you are facing TLE you probably made the same mistake as me.\n\nCorrect Way: When pushing a coordinate to the queue immediately mark it + or add it to your v | b_clodius | NORMAL | 2021-07-10T18:09:25.571299+00:00 | 2021-07-10T18:09:25.571330+00:00 | 8,489 | false | If you are facing TLE you probably made the same mistake as me.\n\n**Correct Way**: When pushing a coordinate to the queue immediately mark it ```+``` or add it to your visited hashset.\n\n```\n for path in range(size):\n row, col = queue.popleft()\n if moves > 0 and (row == len... | 319 | 2 | [] | 26 |
nearest-exit-from-entrance-in-maze | C++ BFS solution || commented | c-bfs-solution-commented-by-saiteja_ball-3olw | A similar problem -\n1765. Map of highest peak\n\nclass Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& e) {\n queue<pa | saiteja_balla0413 | NORMAL | 2021-07-10T16:17:24.455915+00:00 | 2021-07-11T02:21:17.217807+00:00 | 12,155 | false | A similar problem -\n[1765. Map of highest peak](https://leetcode.com/problems/map-of-highest-peak/)\n```\nclass Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& e) {\n queue<pair<int,int>> q;\n q.push({e[0],e[1]});\n\t\t\n\t\t//current moves\n int moves=1;\n ... | 136 | 4 | [] | 22 |
nearest-exit-from-entrance-in-maze | Java || 👍Explained in Detail👍|| Simple & Fast Solution✅|| BFS | java-explained-in-detail-simple-fast-sol-19z2 | I do my best everyday to give a clear explanation, so to help everyone improve their skills.\n\nIf you find this helpful, please \uD83D\uDC4D upvote this post a | cheehwatang | NORMAL | 2022-11-21T01:09:21.023581+00:00 | 2022-11-21T01:37:26.639206+00:00 | 8,037 | false | I do my best everyday to give a clear explanation, so to help everyone improve their skills.\n\nIf you find this **helpful**, please \uD83D\uDC4D **upvote** this post and watch my [Github Repository](https://github.com/cheehwatang/leetcode-java).\n\nThank you for reading! \uD83D\uDE04 Comment if you have any questions ... | 83 | 4 | ['Array', 'Breadth-First Search', 'Matrix', 'Java'] | 9 |
nearest-exit-from-entrance-in-maze | BFS | bfs-by-votrubac-yi4p | C++\ncpp\nint dir[5] = {0, -1, 0, 1, 0};\nint nearestExit(vector<vector<char>>& m, vector<int>& ent) {\n queue<array<int, 3>> q; // i, j, steps\n q.push({ | votrubac | NORMAL | 2021-07-10T16:25:42.359381+00:00 | 2021-07-10T16:53:35.641305+00:00 | 6,549 | false | **C++**\n```cpp\nint dir[5] = {0, -1, 0, 1, 0};\nint nearestExit(vector<vector<char>>& m, vector<int>& ent) {\n queue<array<int, 3>> q; // i, j, steps\n q.push({ent[0], ent[1], 0});\n while(!q.empty()) {\n auto [i, j, steps] = q.front(); q.pop();\n if ((i != ent[0] || j != ent[1]) && (i == 0 || j... | 62 | 3 | [] | 19 |
nearest-exit-from-entrance-in-maze | [python3] BFS (2 styles) with line by line comments O(m*n) | python3-bfs-2-styles-with-line-by-line-c-uqex | BFS is more suitable for searching vertices closer to the given source. BFS is optimal for finding the shortest path.\n- DFS is more suitable when there are sol | MeidaChen | NORMAL | 2022-11-21T06:55:25.294321+00:00 | 2024-01-04T19:21:42.589249+00:00 | 3,600 | false | - BFS is more suitable for searching vertices closer to the given source. BFS is optimal for finding the shortest path.\n- DFS is more suitable when there are solutions away from the source. DFS is not optimal for finding the shortest path.\n\nSo we chose BFS over DFS for this problem of finding the shortest path.\n\n*... | 48 | 2 | [] | 3 |
nearest-exit-from-entrance-in-maze | ✅ [Python/C++] DFS sucks here, go BFS (explained) | pythonc-dfs-sucks-here-go-bfs-explained-uv3po | \u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.\n*\nThis solution employs Breadth First Search* approach to explore the maze. Time complexity is linear: O(m\n) | stanislav-iablokov | NORMAL | 2022-11-21T01:17:48.145458+00:00 | 2022-11-21T04:21:57.676831+00:00 | 4,736 | false | **\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.**\n****\nThis solution employs *Breadth First Search* approach to explore the maze. Time complexity is linear: **O(m\\*n)**. Space complexity is linear: **O(m\\*n)**. \n****\n\n**Comment.** This problem can be solved by using both BFS and DFS, however, the latter seems... | 34 | 3 | [] | 8 |
nearest-exit-from-entrance-in-maze | [Python] Easy DFS MEMOIZATION & BFS | python-easy-dfs-memoization-bfs-by-aatms-p34v | Nearest Exit from Entrance in Maze\n## DFS Idea\n We search from entrance cell for the nearest boundary cell in all four directions and after getting the distan | aatmsaat | NORMAL | 2021-07-10T19:35:59.426878+00:00 | 2021-07-12T06:07:42.669353+00:00 | 4,643 | false | # **Nearest Exit from Entrance in Maze**\n## DFS Idea\n* We search from entrance cell for the nearest boundary cell in all four directions and after getting the distance from all direction, it returns *minimum* of them.\n* Function `reached` checks if currect cell is boundary and not the entrance cell\n* Here `@lru_cac... | 33 | 1 | ['Depth-First Search', 'Breadth-First Search', 'Memoization', 'Python'] | 6 |
nearest-exit-from-entrance-in-maze | 🔥 [LeetCode The Hard Way] 🔥 Explained Line By Line | leetcode-the-hard-way-explained-line-by-ix6u6 | \uD83D\uDD34 Check out LeetCode The Hard Way for more solution explanations and tutorials. \n\uD83D\uDFE0 Check out our Discord for live discussion.\n\uD83D\uDF | __wkw__ | NORMAL | 2022-11-21T03:14:21.029749+00:00 | 2022-11-21T03:14:21.029801+00:00 | 3,114 | false | \uD83D\uDD34 Check out [LeetCode The Hard Way](https://wingkwong.github.io/leetcode-the-hard-way/) for more solution explanations and tutorials. \n\uD83D\uDFE0 Check out our [Discord](https://discord.gg/Nqm4jJcyBf) for live discussion.\n\uD83D\uDFE2 Give a star on [Github Repository](https://github.com/wingkwong/leetco... | 28 | 3 | ['Breadth-First Search', 'Graph', 'C', 'C++'] | 6 |
nearest-exit-from-entrance-in-maze | 📌[C++] Most Intuitive | 🔥BFS | c-most-intuitive-bfs-by-divyamrai-mgbb | Consider looking at some additional BFS-related questions.\n 542. 01 Matrix\n 994. Rotting Oranges\n 1091. Shortest Path in Binary Matrix\n\n------------------- | divyamRai | NORMAL | 2022-11-21T01:48:34.716394+00:00 | 2022-11-21T06:13:04.464937+00:00 | 3,310 | false | # Consider looking at some additional BFS-related questions.\n* [542. 01 Matrix](https://leetcode.com/problems/01-matrix/)\n* [994. Rotting Oranges](https://leetcode.com/problems/rotting-oranges/)\n* [1091. Shortest Path in Binary Matrix](https://leetcode.com/problems/shortest-path-in-binary-matrix/)\n\n---------------... | 20 | 5 | [] | 6 |
nearest-exit-from-entrance-in-maze | Simple BFS (Java) | 7ms | Beats 100% | simple-bfs-java-7ms-beats-100-by-ankitr4-jmfs | The idea is to perform simple breadth first search using a queue. While adding new elements, we perform a simple operation to check if the element being offered | ankitr459 | NORMAL | 2021-07-11T05:49:05.303634+00:00 | 2021-07-11T05:49:54.355472+00:00 | 3,702 | false | The idea is to perform simple breadth first search using a queue. While adding new elements, we perform a simple operation to check if the element being offered exists in first or last row **OR** first or last column.\n\n\n```\nclass Solution {\n public int nearestExit(char[][] maze, int[] entrance) {\n int r... | 20 | 0 | ['Breadth-First Search', 'Queue', 'Java'] | 6 |
nearest-exit-from-entrance-in-maze | Python3 BFS with comments | python3-bfs-with-comments-by-brusht-lgy1 | Idea: use BFS to return shortest path. Since we start BFS from the entrance and iterate level by level, one of our chosen paths will be the minimum (if it exist | brushT | NORMAL | 2021-07-10T16:43:55.507335+00:00 | 2021-07-10T16:43:55.507363+00:00 | 4,235 | false | Idea: use BFS to return shortest path. Since we start BFS from the entrance and iterate level by level, one of our chosen paths will be the minimum (if it exists)\n```\ndef nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n dirs = [(0,1),(0,-1),(1,0),(-1,0)]\n entrance = (entrance[0],... | 19 | 0 | ['Breadth-First Search', 'Python', 'Python3'] | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.