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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
largest-rectangle-in-histogram | C++ stack solution | c-stack-solution-by-eplistical-l09m | The idea is simple: suppose a rectangle contains the column i and has a height heights[i], then the max area of the rectangle will be heights[i] * (rb[i] - lb[i | eplistical | NORMAL | 2020-01-01T19:26:39.392648+00:00 | 2020-01-01T19:26:39.392696+00:00 | 1,055 | false | The idea is simple: suppose a rectangle contains the column `i` and has a height `heights[i]`, then the max area of the rectangle will be `heights[i] * (rb[i] - lb[i] - 1)`. Here we define:\n\n- `lb[i]`: the index of first column on the left of `i` whose height is lower than `heights[i]`.\n- `rb[i]`: the index of first... | 8 | 0 | ['C++'] | 3 |
largest-rectangle-in-histogram | O(n) solution with clear code | on-solution-with-clear-code-by-kuskus87-y84p | The idea is very simple: for each bar find the area of the rectangle where this bar height defines the height of the whole rectangle.\nTo do that in O(n), we ne | kuskus87 | NORMAL | 2019-06-08T12:34:48.431335+00:00 | 2019-06-08T12:34:48.431376+00:00 | 1,127 | false | The idea is very simple: for each bar find the area of the rectangle where this bar height defines the height of the whole rectangle.\nTo do that in O(n), we need to find in O(1) the following indices:\n\t1) Index of the first element on the left from current `i` which is smaller than `heights[i]`\n\t2) Index of the fi... | 8 | 0 | ['C'] | 0 |
largest-rectangle-in-histogram | 16 ms beat 94% c++ solution | 16-ms-beat-94-c-solution-by-pkugoodspeed-i809 | class Solution {\n public:\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size(),Area=0;\n vector<int> lef | pkugoodspeed | NORMAL | 2016-05-24T06:06:03+00:00 | 2016-05-24T06:06:03+00:00 | 844 | false | class Solution {\n public:\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size(),Area=0;\n vector<int> left(n,0),right(n,0);\n for(int i=1;i<n;i++){ \n int j = i-1;\n while(j>=0 && heights[i]<=heights[j]){\n ... | 8 | 0 | [] | 0 |
largest-rectangle-in-histogram | Most optimized Code in Java 💯 | most-optimized-code-in-java-by-no_one_ca-9cox | 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 | No_one_can_stop_me | NORMAL | 2023-03-06T08:10:10.076873+00:00 | 2023-03-06T08:10:28.788443+00:00 | 1,095 | 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. $... | 7 | 0 | ['Java'] | 0 |
largest-rectangle-in-histogram | [Python] Simple Stack Solution | python-simple-stack-solution-by-rowe1227-26du | Key Insights:\n\nFor each index, the largest rectangle of heights h[i] that passes\nthrough the index will have a left bound at the first height lower\nthan h[i | rowe1227 | NORMAL | 2020-12-31T08:52:15.165243+00:00 | 2020-12-31T08:53:21.197945+00:00 | 361 | false | **Key Insights:**\n\nFor each index, the largest rectangle of heights h[i] that passes\nthrough the index will have a left bound at the first height lower\nthan h[i] to the left and a right bound at the first height lower than\nh[i] to the right.\n\n**Approach:**\n\nFor each index:\n1. Find the index of the first short... | 7 | 1 | [] | 0 |
largest-rectangle-in-histogram | [Python] A brief summary for Monotonous Stacks applications | python-a-brief-summary-for-monotonous-st-za5p | For this problem, an monotonously increasing stack is used to store the previous indices. Once current height < stack[-1]\'s height, a cadidate rectangler area | oldeelk | NORMAL | 2020-04-16T07:21:59.402199+00:00 | 2020-04-22T02:58:32.007124+00:00 | 322 | false | For this problem, an monotonously increasing stack is used to store the previous indices. Once `current height` < `stack[-1]\'s height`, a cadidate rectangler area can be calculated with `width: length between stack[-2] + 1 ~ current index - 1`, `height: stack[-1]\'s height`. Compare all candidates to get the final res... | 7 | 0 | [] | 0 |
largest-rectangle-in-histogram | python O(n) explained in detail | python-on-explained-in-detail-by-zxshuat-tmrz | \nclass Solution(object):\n def largestRectangleArea(self, heights):\n """\n :type heights: List[int]\n :rtype: int\n """\n | zxshuati | NORMAL | 2019-06-02T18:54:01.552346+00:00 | 2019-06-02T18:54:01.552387+00:00 | 807 | false | ```\nclass Solution(object):\n def largestRectangleArea(self, heights):\n """\n :type heights: List[int]\n :rtype: int\n """\n # for every bar, calc the area which uses this bar as the lowest bar\n # therefore we need to find the first lower bar towards the left and the \n ... | 7 | 0 | [] | 0 |
largest-rectangle-in-histogram | Easy-to-understand 92ms Python solution, linear time and space. | easy-to-understand-92ms-python-solution-thvnm | class Solution(object):\n # Helper function calculating how far each bar can be extended to the right.\n def calmax(self, height):\n stack = []\n | pei11 | NORMAL | 2015-08-25T23:56:44+00:00 | 2015-08-25T23:56:44+00:00 | 2,299 | false | class Solution(object):\n # Helper function calculating how far each bar can be extended to the right.\n def calmax(self, height):\n stack = []\n n = len(height)\n rec = [0] * n\n for i in xrange(len(height)):\n while len(stack) > 0 and height[stack[-1]] > height[i]:\n ... | 7 | 0 | [] | 2 |
largest-rectangle-in-histogram | 10 lines 🚀 Monotonic Stack | One pass | Dummy node technique | 10-lines-monotonic-stack-one-pass-dummy-cfexb | Intuition\n Describe your approach to solving the problem. \nUsing dummy nodes to avoid edge cases.\n\n# Complexity\n- Time complexity: O(n)\n Add your time com | sulerhy | NORMAL | 2024-10-10T14:55:48.621663+00:00 | 2024-11-21T05:39:40.040292+00:00 | 1,374 | false | # Intuition\n<!-- Describe your approach to solving the problem. -->\nUsing dummy nodes to avoid edge cases.\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(n)$$ -->\n\n# Code\n```python3 []\nclass... | 6 | 0 | ['Monotonic Stack', 'Python3'] | 0 |
largest-rectangle-in-histogram | Python Easy Solution (beats 96%) | python-easy-solution-beats-96-by-brianwu-drv2 | \n\n\n# Intuition\n Describe your first thoughts on how to solve this problem. \nUse ascending monotonic stack to solve this.\n\n# Approach\n Describe your appr | BrianWU-S | NORMAL | 2023-06-13T17:47:01.028964+00:00 | 2023-06-13T17:49:42.145482+00:00 | 1,830 | false | \n\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse ascending monotonic stack to solve this.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n-... | 6 | 0 | ['Monotonic Stack', 'Python3'] | 0 |
largest-rectangle-in-histogram | C++ EasyToUnderstad Stack Solution || ⭐⭐⭐ | c-easytounderstad-stack-solution-by-shai-bvx5 | Intuition\n Describe your first thoughts on how to solve this problem. \nwe will consider heights[i] as a length and check both ways how much it extends to both | Shailesh0302 | NORMAL | 2023-03-29T12:35:21.801733+00:00 | 2023-03-29T12:35:21.801777+00:00 | 865 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nwe will consider heights[i] as a length and check both ways how much it extends to both ways \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFor every heights[i] we will find its next smaller to the right and its ... | 6 | 0 | ['Stack', 'C++'] | 0 |
largest-rectangle-in-histogram | Simple JavaScript Solution | simple-javascript-solution-by-nikki_khar-g2cq | Intuition\n Describe your first thoughts on how to solve this problem. \nJust Solve this Problem like any other stack problem of nearest minimum.\n\n# Approach\ | nikki_kharkwal | NORMAL | 2023-01-22T03:57:49.411003+00:00 | 2023-02-01T13:59:35.824851+00:00 | 862 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nJust Solve this Problem like any other stack problem of nearest minimum.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Find the nearest minimum elements for the left side of the given array.\n2. Find the neare... | 6 | 0 | ['Array', 'Stack', 'Monotonic Stack', 'JavaScript'] | 0 |
largest-rectangle-in-histogram | C++ || O(N) || Easy to Understand with In-Depth Explanation and Examples | c-on-easy-to-understand-with-in-depth-ex-qc0s | Table of Contents\n\n- TL;DR\n - Code\n - Complexity\n- In Depth Analysis\n - Intuition\n - Approach\n - Example\n\n# TL;DR\n\nPrecompute the next smallest | krazyhair | NORMAL | 2022-12-05T22:24:09.376537+00:00 | 2023-01-03T15:52:56.937840+00:00 | 583 | false | #### Table of Contents\n\n- [TL;DR](#tldr)\n - [Code](#code)\n - [Complexity](#complexity)\n- [In Depth Analysis](#in-depth-analysis)\n - [Intuition](#intuition)\n - [Approach](#approach)\n - [Example](#example)\n\n# TL;DR\n\nPrecompute the next smallest height for every height going from left to right and also fr... | 6 | 0 | ['Array', 'Stack', 'Monotonic Stack', 'C++'] | 0 |
largest-rectangle-in-histogram | [C++] Largest Rectangle in Histogram with Stack | c-largest-rectangle-in-histogram-with-st-5ugm | Description\n\nGet the Largest Area of Rectangle in a Histogram with a Monotonic Stack.\n\nProgram\n\ncpp []\nclass Solution {\npublic:\n int largestRectangl | harshcut | NORMAL | 2022-11-17T13:52:52.895890+00:00 | 2022-11-17T13:52:52.895926+00:00 | 1,446 | false | **Description**\n\nGet the Largest Area of Rectangle in a Histogram with a Monotonic Stack.\n\n**Program**\n\n```cpp []\nclass Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int result = 0;\n stack<pair<int, int>> stack;\n for (int i = 0; i < heights.size(); i++) {\n ... | 6 | 0 | ['Stack', 'Monotonic Stack', 'C++'] | 0 |
largest-rectangle-in-histogram | O(N) using single Stack in java | on-using-single-stack-in-java-by-tanx4-bf8u | \nclass Solution {\n public int largestRectangleArea(int[] heights) {\n \n /* Naive Solution \n \n int i;\n int max=height | tanx4 | NORMAL | 2022-09-24T16:38:39.752649+00:00 | 2022-09-24T16:38:39.752689+00:00 | 834 | false | ```\nclass Solution {\n public int largestRectangleArea(int[] heights) {\n \n /* Naive Solution \n \n int i;\n int max=heights[0];\n for(i=0;i<heights.length;i++)\n {\n int sum=heights[i];\n for(int j=i+1;j<heights.length;j++)\n {\n ... | 6 | 0 | ['Stack', 'Java'] | 1 |
largest-rectangle-in-histogram | JAVA|| Array->(O(n^2)) || Easy To Undestand||TL | java-array-on2-easy-to-undestandtl-by-an-7h25 | \n | anmolnegi242 | NORMAL | 2022-08-13T08:57:29.955890+00:00 | 2023-07-01T14:46:49.817895+00:00 | 767 | false | \n | 6 | 0 | ['Array', 'Two Pointers', 'Java'] | 1 |
largest-rectangle-in-histogram | Stack based O(N) with detailed explanation | stack-based-on-with-detailed-explanation-112y | Solution intuition\n\nThe idea to efficiently solve this problem is very simple. Let\'s say we have heights as follows:\n\n\n\nFor any particular height which w | blueblazin | NORMAL | 2022-01-15T03:56:59.344242+00:00 | 2022-01-15T03:56:59.344293+00:00 | 683 | false | ## Solution intuition\n\nThe idea to efficiently solve this problem is very simple. Let\'s say we have heights as follows:\n\n\n\nFor any particular height which we choose,\n\n | java-stack-detailed-explanation-on-by-ja-vavs | \nIntuition :\n1) Max area will always have atleast one full height on any index\n2) Find largest rectangle including each bar one by one.\n\ta) For each bar, W | javed_beingzero | NORMAL | 2021-11-30T04:32:33.513277+00:00 | 2022-01-29T17:16:32.658514+00:00 | 677 | false | ```\nIntuition :\n1) Max area will always have atleast one full height on any index\n2) Find largest rectangle including each bar one by one.\n\ta) For each bar, We have to find it\'s left limit & right limit (to know the maximum width)\n\tb) Find each index\'s left limit and store it in left array\n\t\ti) Traverse lef... | 6 | 0 | ['Stack', 'Java'] | 2 |
largest-rectangle-in-histogram | Standard Interview point of view Stack Solution | standard-interview-point-of-view-stack-s-1ziv | \nclass Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size();\n if(n == 0)\n return 0;\n | sauravgpt | NORMAL | 2021-03-16T08:54:30.049784+00:00 | 2021-03-16T08:54:30.049828+00:00 | 619 | false | ```\nclass Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size();\n if(n == 0)\n return 0;\n \n stack<int> S;\n \n int L[n];\n int R[n];\n \n for(int i=0; i<n; i++) {\n while(!S.empty() && h... | 6 | 0 | ['C'] | 0 |
largest-rectangle-in-histogram | Python by monotone stack [w/ Comment] | python-by-monotone-stack-w-comment-by-br-f2zl | Python by monotone stack \n\n---\n\nImplementation:\n\n\nclass Solution:\n def largestRectangleArea(self, heights: List[int]) -> int:\n \n # st | brianchiang_tw | NORMAL | 2021-02-26T10:30:43.319572+00:00 | 2021-02-26T10:30:43.319599+00:00 | 1,230 | false | Python by monotone stack \n\n---\n\n**Implementation**:\n\n```\nclass Solution:\n def largestRectangleArea(self, heights: List[int]) -> int:\n \n # store x coordination, init as -1\n stack = [ -1 ]\n \n # add zero as dummy tail \n heights.append( 0 )\n \n # top... | 6 | 0 | ['Math', 'Monotonic Stack', 'Python', 'Python3'] | 0 |
largest-rectangle-in-histogram | [Java] Another thought using divide and conquer | java-another-thought-using-divide-and-co-aec3 | We can find the minimum height and the histogram can be divided into two part, left and right.\nThe ans must be among the mid(minimum) height times the length o | nanotrt2333 | NORMAL | 2020-07-27T04:48:27.622919+00:00 | 2020-09-06T23:42:58.856649+00:00 | 285 | false | We can find the minimum height and the histogram can be divided into two part, left and right.\nThe ans must be among the mid(minimum) height times the length of the interval, or the largest area from either side.\nThen we can come up with a working code,\n```\nclass Solution {\n public int largestRectangleArea(int[... | 6 | 0 | [] | 0 |
largest-rectangle-in-histogram | My Accepted short Java Solution | my-accepted-short-java-solution-by-tatek-nemi | \nclass Solution {\n public int largestRectangleArea(int[] heights) {\n int answer = 0;\n for(int i = 0; i < heights.length; i++){\n | tatek | NORMAL | 2019-11-14T02:53:58.626925+00:00 | 2019-11-14T02:53:58.626973+00:00 | 755 | false | ```\nclass Solution {\n public int largestRectangleArea(int[] heights) {\n int answer = 0;\n for(int i = 0; i < heights.length; i++){\n int currentHeight = heights[i];\n int left = i, right = i;\n while(left >= 0 && heights[left] >= currentHeight) left--;\n w... | 6 | 0 | ['Java'] | 3 |
largest-rectangle-in-histogram | C# Solution | c-solution-by-leonhard_euler-v81q | \npublic class Solution \n{\n public int LargestRectangleArea(int[] heights) \n {\n int n = heights.Length, max = 0;\n var stack = new Stack | Leonhard_Euler | NORMAL | 2019-11-12T05:22:10.242176+00:00 | 2019-11-12T05:22:10.242257+00:00 | 426 | false | ```\npublic class Solution \n{\n public int LargestRectangleArea(int[] heights) \n {\n int n = heights.Length, max = 0;\n var stack = new Stack<int>();\n for(int i = 0; i <= n; i++)\n {\n var height = i < n ? heights[i] : 0;\n while(stack.Count != 0 && heights[sta... | 6 | 0 | [] | 0 |
largest-rectangle-in-histogram | Recursive JAVA solution in O(nLogn) | recursive-java-solution-in-onlogn-by-nis-qdf8 | \n\tprivate static int largestRectangleArea(int[] heights) {\n if (heights == null || heights.length == 0)\n return 0;\n\n //utility fu | nishantbhb | NORMAL | 2019-06-30T09:12:08.058352+00:00 | 2019-06-30T09:17:14.208101+00:00 | 775 | false | ```\n\tprivate static int largestRectangleArea(int[] heights) {\n if (heights == null || heights.length == 0)\n return 0;\n\n //utility function to divide and conquer\n return maxRectangle(heights, 0, heights.length - 1);\n }\n\n private static int maxRectangle(int[] arr, int l, in... | 6 | 1 | ['Divide and Conquer', 'Recursion', 'Java'] | 5 |
largest-rectangle-in-histogram | (( Swift )) 100% Beaten - Using Stack Trick... O(N) RunTime ComPlexiTY | swift-100-beaten-using-stack-trick-on-ru-w4fz | \nclass Solution {\n func largestRectangleArea(_ heights: [Int]) -> Int {\n \n var heights = heights\n heights.append(0)\n \n | nraptis | NORMAL | 2019-06-20T23:24:42.423615+00:00 | 2019-06-20T23:24:42.423683+00:00 | 319 | false | ```\nclass Solution {\n func largestRectangleArea(_ heights: [Int]) -> Int {\n \n var heights = heights\n heights.append(0)\n \n var result = 0\n \n var stack = [Int]()\n \n for i in heights.indices {\n \n while stack.count > 0 && h... | 6 | 0 | [] | 1 |
largest-rectangle-in-histogram | 4ms Java solution, using O(n) stack space, O(n) time | 4ms-java-solution-using-on-stack-space-o-idtv | public class Solution {\n public int largestRectangleArea(int[] height) {\n if ((height == null) || (height.length == 0)) return 0;\n | gliangtao | NORMAL | 2015-11-22T19:17:01+00:00 | 2015-11-22T19:17:01+00:00 | 3,014 | false | public class Solution {\n public int largestRectangleArea(int[] height) {\n if ((height == null) || (height.length == 0)) return 0;\n final int N = height.length;\n int[] s = new int[N + 1];\n int i, top = 0, hi, area = 0;\n s[0] = -1;\n for (... | 6 | 1 | ['Stack', 'Java'] | 7 |
largest-rectangle-in-histogram | Largest Rectangle in Histogram [C++] | largest-rectangle-in-histogram-c-by-move-ratb | IntuitionTo solve the problem of finding the largest rectangle area in a histogram, we need to consider how to efficiently calculate the area of the largest rec | moveeeax | NORMAL | 2025-01-22T15:31:26.331273+00:00 | 2025-01-22T15:31:26.331273+00:00 | 594 | false | # Intuition
To solve the problem of finding the largest rectangle area in a histogram, we need to consider how to efficiently calculate the area of the largest rectangle that can be formed within the bounds of the histogram. The key insight is to use a stack to keep track of the indices of the bars in the histogram, wh... | 5 | 2 | ['C++'] | 0 |
largest-rectangle-in-histogram | NO STACK used, only vector!! | no-stack-used-only-vector-by-strange_qua-ij2h | Intuition \n Describe your first thoughts on how to solve this problem. \nSee this problem is little (un-intuitive) but pure logic. Just focus on the pattern of | strange_quark | NORMAL | 2024-09-20T12:03:51.656984+00:00 | 2024-09-21T18:34:04.676337+00:00 | 722 | false | # Intuition \n<!-- Describe your first thoughts on how to solve this problem. -->\nSee this problem is little (un-intuitive) but pure logic. Just focus on the pattern of given a height value at some position i, is the (i + 1)th position is bigger/equal or smaller than the current value.\n\n# Approach\n<!-- Describe you... | 5 | 0 | ['C++'] | 1 |
largest-rectangle-in-histogram | 💥[EXPLAINED] TypeScript. Runtime beats 99.47% | explained-typescript-runtime-beats-9947-i0x19 | Intuition\nUse a stack to efficiently track the indices of histogram bars. The stack helps determine the width of rectangles formed with each bar as the shortes | r9n | NORMAL | 2024-08-22T10:37:39.273273+00:00 | 2024-08-26T19:52:57.264604+00:00 | 121 | false | # Intuition\nUse a stack to efficiently track the indices of histogram bars. The stack helps determine the width of rectangles formed with each bar as the shortest bar in the rectangle.\n\n# Approach\nUse a stack to track bar indices. For each bar, pop from the stack when encountering a shorter bar, calculating the max... | 5 | 0 | ['TypeScript'] | 0 |
largest-rectangle-in-histogram | Simplest and Easiest Solution ️🔥 | O(n) | C++ | ️ | simplest-and-easiest-solution-on-c-by-va-5223 | Intuition\nTo find the largest rectangle in a histogram, we need to determine the largest possible rectangular area that can be formed using consecutive bars. T | vaib8557 | NORMAL | 2024-06-10T05:50:44.074508+00:00 | 2024-06-10T05:50:44.074547+00:00 | 1,799 | false | # Intuition\nTo find the largest rectangle in a histogram, we need to determine the largest possible rectangular area that can be formed using consecutive bars. The key idea is to efficiently find the next smaller element and the previous smaller element for each bar. Using these, we can compute the width of the rectan... | 5 | 0 | ['C++'] | 0 |
largest-rectangle-in-histogram | Monotonic Stack Pattern deep understanding | monotonic-stack-pattern-deep-understandi-5n5u | Introduction To stack and NEG pattern - 4 variations covered in\n\n232. Implement Queue using Stacks\n225. Implement Stack using Queues\n155. Min Stack\n496. Ne | Dixon_N | NORMAL | 2024-05-17T19:44:27.714838+00:00 | 2024-05-24T21:30:46.802621+00:00 | 930 | false | Introduction To stack and NEG pattern - **4 variations** covered in\n\n[232. Implement Queue using Stacks](https://leetcode.com/problems/implement-queue-using-stacks/solutions/5203561/implement-queue-using-stacks/)\n[225. Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues/solutions... | 5 | 0 | ['Java'] | 0 |
largest-rectangle-in-histogram | Easy to understand Backtracking and Stack Approach | easy-to-understand-backtracking-and-stac-euwe | Intuition\n Describe your first thoughts on how to solve this problem. \nEasy method to do the question.\n# Approach\n Describe your approach to solving the pro | ShivaanjayNarula | NORMAL | 2024-05-10T22:49:23.834256+00:00 | 2024-05-10T22:49:23.834287+00:00 | 169 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nEasy method to do the question.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nPrevious and Next Arrays: The previous and nexts functions are used to create two arrays, prev and next, which store the indices of the ... | 5 | 0 | ['Backtracking', 'Stack', 'Recursion', 'C++'] | 0 |
largest-rectangle-in-histogram | Monotonic stack vs DP||37ms Beats 99.98% | monotonic-stack-vs-dp37ms-beats-9998-by-3ucng | Intuition\n Describe your first thoughts on how to solve this problem. \nThe same method can generalized to solve 85. Maximal Rectangle\n\n2 approaches are prov | anwendeng | NORMAL | 2024-04-18T12:29:11.136594+00:00 | 2024-04-18T12:29:11.136618+00:00 | 1,294 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe same method can generalized to solve [85. Maximal Rectangle](https://leetcode.com/problems/maximal-rectangle/solutions/5014468/monotonic-stackdpcount-successive-1s16ms-beats-9962/)\n\n2 approaches are provided. The monotonic stack met... | 5 | 0 | ['Dynamic Programming', 'Monotonic Stack', 'C++'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | [C++/Java/Python] From Straightforward to Optimized Bitmask DP - O(2^n * n) - Clean & Concise | cjavapython-from-straightforward-to-opti-yyjj | \u2714\uFE0F Solution 1: Straightforward Bitmask DP\n- Let dp(mask, remainTime) is the minimum of work sessions needed to finish all the tasks represent by mask | hiepit | NORMAL | 2021-08-31T13:34:07.662485+00:00 | 2021-09-01T03:15:46.029919+00:00 | 11,809 | false | **\u2714\uFE0F Solution 1: Straightforward Bitmask DP**\n- Let `dp(mask, remainTime)` is the minimum of work sessions needed to finish all the tasks represent by `mask` (where `i`th bit = 1 means tasks[i] need to proceed) with the `remainTime` we have for the current session.\n- Then `dp((1 << n) - 1, 0)` is our result... | 180 | 1 | [] | 12 |
minimum-number-of-work-sessions-to-finish-the-tasks | C++ Solution | Recursion + Memoization | c-solution-recursion-memoization-by-invu-9eiq | Wrong Greedy Approach:\n\n- Sort the tasks array and keep adding the task to the current session until the sum becomes equal to or more than the sessionTime.\n- | invulnerable | NORMAL | 2021-08-29T04:01:58.689715+00:00 | 2021-08-29T04:01:58.689760+00:00 | 17,293 | false | Wrong Greedy Approach:\n\n- Sort the `tasks` array and keep adding the task to the current session until the sum becomes equal to or more than the `sessionTime`.\n- This approach fails on test cases like `tasks` = {3, 4, 7, 8, 10} `sessionTime` = 12\n\n**Solution:**\n\nWe have created a vector named `sessions`. The len... | 178 | 10 | [] | 32 |
minimum-number-of-work-sessions-to-finish-the-tasks | Easier than top voted ones | LegitClickbait | c++ | easier-than-top-voted-ones-legitclickbai-dezv | Algorithm\n1. We use 2 things -> mask to denote which elements are processed. If ith bit is 1 means ith element is processed. -> currentTime we start with 0 as | shourabhpayal | NORMAL | 2021-08-29T05:55:56.436519+00:00 | 2021-08-30T06:46:24.641428+00:00 | 7,108 | false | **Algorithm**\n1. We use 2 things -> ```mask``` to denote which elements are processed. If ```ith``` bit is 1 means ```ith``` element is processed. -> ```currentTime``` we start with 0 as current time.\n2. At each call go through all the unprocessed elements only.\n3. We can choose to include the ith unprocessed elemen... | 106 | 5 | ['Dynamic Programming', 'Bit Manipulation', 'C'] | 22 |
minimum-number-of-work-sessions-to-finish-the-tasks | [Python] dynamic programming on subsets, explained | python-dynamic-programming-on-subsets-ex-d6rp | You can see that in this problem n <= 14, so we need to apply some kind of bruteforce algorithm. If we try just n! options, it will be too big, so the idea is t | dbabichev | NORMAL | 2021-08-29T04:01:33.963104+00:00 | 2021-08-29T09:28:38.249476+00:00 | 7,599 | false | You can see that in this problem `n <= 14`, so we need to apply some kind of bruteforce algorithm. If we try just `n!` options, it will be too big, so the idea is to use dynamic programming on subsets. Let `dp(mask)`, where `mask` is bitmask of already used jobs be the tuple of numbers: first one is number of sessions ... | 86 | 8 | ['Dynamic Programming', 'Bitmask'] | 12 |
minimum-number-of-work-sessions-to-finish-the-tasks | [Python] Clean & Simple, no bitmask | python-clean-simple-no-bitmask-by-yo1995-b5d9 | The full problem is NP-hard: https://en.wikipedia.org/wiki/Bin_packing_problem\n\nTo get the exact result, we have to recurse with some smart memorization techn | yo1995 | NORMAL | 2021-08-29T04:26:02.778483+00:00 | 2021-08-29T04:30:05.795818+00:00 | 4,814 | false | The full problem is NP-hard: https://en.wikipedia.org/wiki/Bin_packing_problem\n\nTo get the exact result, we have to recurse with some smart memorization techniques.\n\nI still find it challenging to use bitmask, so here is the dfs version.\n\nComparing to the default dfs which gets TLE, the trick here is to loop thro... | 64 | 0 | ['Python'] | 11 |
minimum-number-of-work-sessions-to-finish-the-tasks | C++ & Java Bitmask DP with Explanation time: O(n * 2^n) space: O(2^n) | c-java-bitmask-dp-with-explanation-time-ac0yu | dp[mask] = {a, b} where\na - minimum number of session\nb - minimum time of last session\nThe idea is to go through all tasks who belong to mask and optimally c | felixhuang07 | NORMAL | 2021-08-29T04:01:03.912852+00:00 | 2021-09-04T06:08:58.259600+00:00 | 5,762 | false | dp[mask] = {a, b} where\na - minimum number of session\nb - minimum time of last session\nThe idea is to go through all tasks who belong to mask and optimally choose the last task \'t\' that was added to last session.\n\nSimilar problem: CSES Problem Set - Elevator Rides https://cses.fi/problemset/task/1653\nThis is ex... | 50 | 1 | ['Dynamic Programming', 'C', 'Bitmask', 'Java'] | 10 |
minimum-number-of-work-sessions-to-finish-the-tasks | JAVA solution 15ms DFS + Pruning | java-solution-15ms-dfs-pruning-by-kge-oreo | The pruning - you only need to put the first k tasks in first k sessions.\n\nFor example, assume you are trying if the tasks can be assgiend to 5 sessions (i.e. | kge | NORMAL | 2021-08-29T05:49:01.058615+00:00 | 2021-08-30T06:15:16.389425+00:00 | 3,618 | false | The pruning - you only need to put the first k tasks in first k sessions.\n\nFor example, assume you are trying if the tasks can be assgiend to 5 sessions (i.e., n == 5).\n\n- When you run DFS for the first task, you see 5 empty sessions. It doesn\'t matter which session the task is assgiend to, becasue all of the 5 s... | 38 | 0 | [] | 10 |
minimum-number-of-work-sessions-to-finish-the-tasks | Python | Backtracking | 664ms | 100% time and space | Explanation | python-backtracking-664ms-100-time-and-s-v68y | I think the test cases are little weak, because I just did backtracking and a little pruning and seems to be 4x faster than bitmask solutions.\n The question bo | detective_dp | NORMAL | 2021-08-29T14:54:17.225745+00:00 | 2021-08-30T20:36:52.024589+00:00 | 3,051 | false | * I think the test cases are little weak, because I just did backtracking and a little pruning and seems to be 4x faster than bitmask solutions.\n* The question boils down to finding minimum number of subsets such that each subset sum <= sessionTime. I maintain a list called subsets, where I track each subset sum. For ... | 30 | 0 | ['Backtracking', 'Python3'] | 2 |
minimum-number-of-work-sessions-to-finish-the-tasks | C++ DFS with pruning | c-dfs-with-pruning-by-mingrui-48x4 | \nclass Solution {\n vector<int> tasks;\n int sessionTime;\n int result;\n vector<int> sessions;\n void dfs(int idx) {\n if (sessions.size | mingrui | NORMAL | 2021-08-29T04:02:25.026920+00:00 | 2021-08-29T04:07:22.397882+00:00 | 2,824 | false | ```\nclass Solution {\n vector<int> tasks;\n int sessionTime;\n int result;\n vector<int> sessions;\n void dfs(int idx) {\n if (sessions.size() >= result) {\n return;\n }\n if (idx == tasks.size()) {\n result = sessions.size();\n return;\n }\n ... | 26 | 1 | [] | 6 |
minimum-number-of-work-sessions-to-finish-the-tasks | C++ | Backtracking | c-backtracking-by-believe_itt-314o | 1.Here we will create groups of hours whose sum is less than SessionTime .\n2.basically we will store only the sum of hours in grps array which is less than Ses | Believe_itt | NORMAL | 2021-08-29T07:34:29.970555+00:00 | 2021-08-29T07:35:51.274740+00:00 | 2,358 | false | 1.Here we will create **groups** of hours whose sum is less than `SessionTime` .\n2.basically we will store only the sum of hours in `grps` array which is less than `SessionTime` .\n3.Our aim is to minimize such number of groups to get minimum number of week sessions.\n\nSo, this is how we gonna create `grps` array : ... | 22 | 1 | ['Backtracking', 'C', 'C++'] | 3 |
minimum-number-of-work-sessions-to-finish-the-tasks | C++ || TSP variation || simple explaination | c-tsp-variation-simple-explaination-by-k-6gix | variation of "Travelling salesman Problem"\n \n \n // we will choose a task from the set of un-completed task using bit-mask.\n // if t | kraabhi | NORMAL | 2021-08-29T04:02:51.344192+00:00 | 2021-08-29T04:02:51.344221+00:00 | 2,300 | false | variation of "Travelling salesman Problem"\n \n \n // we will choose a task from the set of un-completed task using bit-mask.\n // if time required to do this task + time exhuasted in prev task is less than or equal to sessionTime then we can do this task in same session .\n // otherwise, w... | 20 | 2 | [] | 6 |
minimum-number-of-work-sessions-to-finish-the-tasks | DFS + Memo + Pruning (12 ms) | dfs-memo-pruning-12-ms-by-votrubac-j7xp | This is a multi-knapsack problem, which is very tough. Fortunately, it\u2019s constrained to 14 tasks. We won\u2019t have more than 14 sessions - each up to 15 | votrubac | NORMAL | 2021-08-29T04:17:07.424994+00:00 | 2021-08-29T04:32:29.731177+00:00 | 3,800 | false | This is a multi-knapsack problem, which is very tough. Fortunately, it\u2019s constrained to 14 tasks. We won\u2019t have more than 14 sessions - each up to 15 hours long. Therefore, we can represent the sessions state using 64-bit.\n\nThe most important optimization is to sort sessions before computing the state. The ... | 19 | 3 | ['C'] | 5 |
minimum-number-of-work-sessions-to-finish-the-tasks | C++ || DP + Bitmask || Recursion Memo BItmask || | c-dp-bitmask-recursion-memo-bitmask-by-i-p2w9 | Idea is to create a mask (n bits) to track if ith task has been performed or not. \nIf not, then we have 2 choices : \n1. Pick it and perform it in current runn | i_quasar | NORMAL | 2021-09-13T01:30:54.452950+00:00 | 2021-09-13T01:38:10.533479+00:00 | 1,390 | false | Idea is to create a mask (n bits) to track if *ith* task has been performed or not. \nIf not, then we have 2 choices : \n1. Pick it and perform it in current running session : \n2. Pick it and create a new session to perform it : \n\nHere dp(mask, time) is the minimum number of sessions needed to finish all the tasks r... | 17 | 0 | ['Dynamic Programming', 'C', 'Bitmask'] | 1 |
minimum-number-of-work-sessions-to-finish-the-tasks | Python [k-subset sums] | python-k-subset-sums-by-gsan-qdwz | For a given value of k you can check if you can have k-subsets where none of the sums exceed T. Start from the lowest possible value of k and try if you can sol | gsan | NORMAL | 2021-08-29T04:04:52.349375+00:00 | 2021-08-29T04:04:52.349401+00:00 | 1,892 | false | For a given value of `k` you can check if you can have `k`-subsets where none of the sums exceed `T`. Start from the lowest possible value of `k` and try if you can solve. `k`-subset sums can be checked with backtracking.\n\n```python\nclass Solution:\n def minSessions(self, A, T):\n A.sort(reverse = True)\n ... | 17 | 2 | [] | 5 |
minimum-number-of-work-sessions-to-finish-the-tasks | Clean Java | clean-java-by-rexue70-afi7 | Use backtring and prune, we have a sessions buckets, we put each task into any one of "not full" one, we prefer to put into old buckets than into new empty buck | rexue70 | NORMAL | 2021-08-29T06:04:33.788221+00:00 | 2021-09-04T02:14:54.379268+00:00 | 1,735 | false | Use backtring and prune, we have a sessions buckets, we put each task into any one of "not full" one, we prefer to put into old buckets than into new empty buckets cause this would incrase speed.\n\n```\n//1ms Accept\nclass Solution {\n int res;\n int maxSessionTime;\n int[] tasks;\n int[] sessions;\n pu... | 14 | 3 | [] | 6 |
minimum-number-of-work-sessions-to-finish-the-tasks | Simple C++ Backtracking + DP solution with comments | simple-c-backtracking-dp-solution-with-c-ecyw | Basic Idea\nThe idea here is to use Backtracking + DP in order to solve this problem under the given constraints.\n\nIntution:\nThe basic intution we are going | rishabh_devbanshi | NORMAL | 2021-08-29T06:22:41.837288+00:00 | 2021-08-29T06:22:41.837318+00:00 | 857 | false | **Basic Idea**\nThe idea here is to use **Backtracking + DP** in order to solve this problem under the given constraints.\n\n**Intution:**\nThe basic intution we are going to use is that every element in the tasks array can either be included in its own separate session or in any one of the existing sessions. Whatever ... | 9 | 0 | ['Dynamic Programming', 'C'] | 5 |
minimum-number-of-work-sessions-to-finish-the-tasks | Python 3 || 15 lines, dp, bisect_left || T/S: 97% / 52% | python-3-15-lines-dp-bisect_left-ts-97-5-mp0p | \npython3 []\nclass Solution:\n def minSessions(self, tasks: List[int], sessionTime: int) -> int:\n\n def canFinish(x: int)-> bool:\n\n @lr | Spaulding_ | NORMAL | 2024-08-28T17:59:10.595880+00:00 | 2024-08-28T18:31:36.243932+00:00 | 242 | false | \n```python3 []\nclass Solution:\n def minSessions(self, tasks: List[int], sessionTime: int) -> int:\n\n def canFinish(x: int)-> bool:\n\n @lru_cache(None)\n def dp(idx: int, slots: tuple)-> bool:\n\n if idx == n: return True\n update, task = list(slots), ta... | 8 | 0 | ['Python3'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | Simple C++ solution | simple-c-solution-by-rac101ran-yk05 | \nclass Solution {\npublic:\n int ans=INT_MAX;\n int minSessions(vector<int>& tasks, int sessions) {\n vector<int> subs;\n solve(0,tasks,s | rac101ran | NORMAL | 2021-09-10T11:12:50.283977+00:00 | 2021-09-10T11:12:50.284005+00:00 | 797 | false | ```\nclass Solution {\npublic:\n int ans=INT_MAX;\n int minSessions(vector<int>& tasks, int sessions) {\n vector<int> subs;\n solve(0,tasks,subs,sessions);\n return ans;\n }\n void solve(int pos,vector<int> &tasks,vector<int>&subs,int sessions) {\n if(pos>=tasks.size()) {\n... | 7 | 0 | ['Backtracking'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | Java O(n! log(n)) Binary Search + Recursion (0ms, beats 100%) | java-on-logn-binary-search-recursion-0ms-zip3 | Instead of searching for the best answer using classic recursion + pruning, assume the aswer and check if it\'s possible to reach it. Search scope for given con | migfulcrum | NORMAL | 2021-08-29T22:09:54.211547+00:00 | 2021-08-31T08:53:31.533306+00:00 | 984 | false | Instead of searching for the best answer using classic recursion + pruning, assume the aswer and check if it\'s possible to reach it. Search scope for given constraints is very small. Sorting elements desc, allows to verify asserted value much faster.\n`sessions` store all times assigned to days `k` so far.\n`si `- ind... | 7 | 0 | ['Recursion', 'Binary Tree'] | 3 |
minimum-number-of-work-sessions-to-finish-the-tasks | Tricky question leetcode well written 👏 and for the record Beats 100% | tricky-question-leetcode-well-written-an-tigv | Tricky question from 698. Partition to K Equal Sum Subsets leetcode well written \uD83D\uDC4F\n\nThe explanation may be lenthy .. but its woth explaining to the | Dixon_N | NORMAL | 2024-08-28T13:07:49.157251+00:00 | 2024-08-28T15:00:06.471210+00:00 | 362 | false | Tricky question from 698. Partition to K Equal Sum Subsets leetcode well written \uD83D\uDC4F\n\nThe explanation may be lenthy .. but its woth explaining to the interviewer \n\nHave fun with this one \uD83C\uDF40\uD83D\uDE80\n\n[For the record Beats 100% ](https://leetcode.com/problems/minimum-number-of-work-sessions-t... | 6 | 0 | ['Backtracking', 'Java'] | 4 |
minimum-number-of-work-sessions-to-finish-the-tasks | C++|| very easy binary-search solution|| k subset partition prob | c-very-easy-binary-search-solution-k-sub-qnmh | \nclass Solution {\npublic:\n bool check(vector<int>&nums,vector<int>&vec,int step,int val)\n {\n if(step>=nums.size()) return true;\n int c | Blue_tiger | NORMAL | 2022-06-13T20:20:53.596004+00:00 | 2022-06-13T20:20:53.596047+00:00 | 617 | false | ```\nclass Solution {\npublic:\n bool check(vector<int>&nums,vector<int>&vec,int step,int val)\n {\n if(step>=nums.size()) return true;\n int cur=nums[step];\n for(int i=0;i<vec.size();i++)\n {\n if(vec[i]+cur<=val)\n {\n vec[i]+=cur;\n ... | 6 | 0 | ['Backtracking', 'Binary Search Tree'] | 2 |
minimum-number-of-work-sessions-to-finish-the-tasks | Java DFS solution beating 100 % | java-dfs-solution-beating-100-by-shuashu-u8ez | ```\nclass Solution {\n public int minSessions(int[] tasks, int sessionTime) {\n // sort desendingly\n // we know that the minSessionTimes is b | shuashuashua1997 | NORMAL | 2021-09-05T05:39:52.300686+00:00 | 2021-09-05T05:39:52.300728+00:00 | 794 | false | ```\nclass Solution {\n public int minSessions(int[] tasks, int sessionTime) {\n // sort desendingly\n // we know that the minSessionTimes is between 1 to # number of tasks\n // then we can use dfs to find from 1 to n, which one works first\n // Copy Right to a classmate.\n Arrays.... | 6 | 1 | [] | 1 |
minimum-number-of-work-sessions-to-finish-the-tasks | C++ | 3ms | Greedy | Binary Search | DFS | c-3ms-greedy-binary-search-dfs-by-alex39-hus5 | we alway choose the max of the tasks to fill in the session.\nthen we use dfs to fill the remaining space in the session from the big to small,\nand we use Bina | alex391a | NORMAL | 2021-08-30T15:39:53.257444+00:00 | 2021-08-30T15:39:53.257488+00:00 | 265 | false | we alway choose the max of the tasks to fill in the session.\nthen we use dfs to fill the remaining space in the session from the big to small,\nand we use Binary Search to find the max one that less than remaining space.\n3ms\n```\nclass Solution {\npublic:\n int minSessions(vector<int>& tasks, int sessionTime) {\n... | 6 | 2 | [] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | [Java] Bin Packing problem | java-bin-packing-problem-by-shk10-gbz0 | Problem at hand is essentially the well known Bin Packing Problem which is NP-hard.\ntasks[i] \u21D2 size of an item or items[i]\nsessionTime \u21D2 capacity of | shk10 | NORMAL | 2021-08-30T13:09:40.735713+00:00 | 2021-08-30T22:44:18.748462+00:00 | 2,846 | false | Problem at hand is essentially the well known [Bin Packing Problem](https://en.wikipedia.org/wiki/Bin_packing_problem) which is NP-hard.\ntasks[i] \u21D2 size of an item or items[i]\nsessionTime \u21D2 capacity of each bin\nGoal: minimize the number of sessions \u21D2 minimize the number of bins\n\nThere are couple of ... | 6 | 0 | [] | 1 |
minimum-number-of-work-sessions-to-finish-the-tasks | [Python3] Bitmask DP - Detailed Explanation | python3-bitmask-dp-detailed-explanation-1w57k | Intuition\n Describe your first thoughts on how to solve this problem. \n- We have to try all possible cases to find minimum number of work session -> DP signal | dolong2110 | NORMAL | 2024-09-12T16:36:03.835408+00:00 | 2024-09-12T16:36:03.835439+00:00 | 170 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- We have to try all possible cases to find minimum number of work session -> DP signal.\n- `1 <= n <= 14` the number of tasks is small enough to save all states using a bit number.\n\n# Approach\n<!-- Describe your approach to solving th... | 5 | 0 | ['Array', 'Dynamic Programming', 'Bit Manipulation', 'Bitmask', 'Python3'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | [Python 3] DFS + Binary search, 32ms | python-3-dfs-binary-search-32ms-by-ladyk-eljn | ```\ndef minSessions(self, tasks: List[int], sessionTime: int) -> int:\n def dfs(i):\n if i == len(tasks):\n return True\n | ladykkk | NORMAL | 2021-11-18T06:37:26.445062+00:00 | 2021-11-18T06:46:09.147959+00:00 | 1,003 | false | ```\ndef minSessions(self, tasks: List[int], sessionTime: int) -> int:\n def dfs(i):\n if i == len(tasks):\n return True\n for j in range(mid):\n if cnt[j] >= tasks[i]:\n cnt[j] -= tasks[i]\n if dfs(i + 1):\n ... | 5 | 0 | ['Binary Tree', 'Python'] | 3 |
minimum-number-of-work-sessions-to-finish-the-tasks | c++ random approach works | c-random-approach-works-by-dan_zhixu-t6lz | People have pointed out that sorting the tasks and then greedily add each task cannot solve the problem, but we can try randomly shuffle the tasks and use the g | dan_zhixu | NORMAL | 2021-08-31T11:09:20.402850+00:00 | 2021-08-31T11:09:20.402892+00:00 | 363 | false | People have pointed out that sorting the tasks and then greedily add each task cannot solve the problem, but we can try randomly shuffle the tasks and use the greedy approach. It works for this problem since the data set is not so large. \n```\nclass Solution {\npublic:\n int minSessions(vector<int>& tasks, int sess... | 5 | 0 | [] | 1 |
minimum-number-of-work-sessions-to-finish-the-tasks | C++ solution | Faster than 100% of C++ soltutions | No complex Algo | Easy to understand | c-solution-faster-than-100-of-c-soltutio-oyzo | Explanation:\nCreate an array state of size of sessionTime initialized as 1 for all the values in tasks and 0 elsewhere. Loop it out, trying to push as many tas | mag_14 | NORMAL | 2021-08-29T05:36:16.976264+00:00 | 2021-08-29T05:36:16.976308+00:00 | 499 | false | **Explanation:**\nCreate an array `state` of size of `sessionTime` initialized as 1 for all the values in `tasks` and 0 elsewhere. Loop it out, trying to push as many `tasks` as possible with sum not more than `sessionTime`, else break. Decrement all the values of `state` array that get executed to avoid repetitions. ... | 5 | 3 | ['Dynamic Programming', 'C'] | 4 |
minimum-number-of-work-sessions-to-finish-the-tasks | Java || Beats 99.37% || 1ms || Binary Search || Backtracking || clear and simple Explanation | java-beats-9937-1ms-binary-search-backtr-j1dg | \n## Minimum Number of Work Sessions to Finish the Tasks\n\nProblem:\n\nYou are given a set of tasks represented by an integer array tasks, where tasks[i] repre | devchaitanya27 | NORMAL | 2023-07-01T11:49:43.096232+00:00 | 2023-07-01T11:49:43.096259+00:00 | 507 | false | \n## Minimum Number of Work Sessions to Finish the Tasks\n\n**Problem:**\n\nYou are given a set of tasks represented by an integer array `tasks`, where `tasks[i]` represents the number of hours required to finish the ith task. You work in sessions, where each session has a maximum duration of `sessionTime` hours. You n... | 4 | 0 | ['Binary Search', 'Backtracking', 'Recursion', 'Java'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | Bit Mask DP | C++ Solution | | bit-mask-dp-c-solution-by-solvedorerror-qcas | Intution\n1. We can Solve this question with Recusion ( But it Takes a lot higher time) (Generally T.C. -> O( N ! * N))\n2. In Recursive Solution of such type o | solvedORerror | NORMAL | 2023-06-12T07:55:32.324631+00:00 | 2023-06-12T07:55:32.324681+00:00 | 587 | false | **Intution**\n1. We can Solve this question with Recusion ( But it Takes a lot higher time) (Generally T.C. -> O( N ! * N))\n2. In Recursive Solution of such type of Problems, we need to modify the original array OR take a **Visited array** to Remember wich indices are visited.\n3. so essentially the if we wanna memoi... | 4 | 0 | ['Dynamic Programming', 'Bitmask'] | 1 |
minimum-number-of-work-sessions-to-finish-the-tasks | Backtracking Solution | Java | Simpler to understand | backtracking-solution-java-simpler-to-un-ragy | The idea is to populate the tasks in such groups such that we can fit in optimal tasks together and at the same time maintain the threshold for a given session. | architgajpal | NORMAL | 2022-11-03T21:35:46.423901+00:00 | 2022-11-03T21:35:46.423940+00:00 | 1,368 | false | The idea is to populate the tasks in such groups such that we can fit in optimal tasks together and at the same time maintain the threshold for a given session. \n\nTo handle this, let us try to group them initially all independently and then backtrack to find space in any of the buckets and add the task to that bucket... | 4 | 0 | ['Backtracking', 'Java'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | JAVA|| BITMASKING + DP || RECURSIVELY | java-bitmasking-dp-recursively-by-asppan-rpze | SUPPOSE YOU HAVE [9,6,9] AND SEESIONTIME=14\nSO U CAN MAKE A BITMASK 000\nWHEN YOU TAKE 9 BIT MASK BECOMES 1000 AS 9 IS LESS THAN 14 YOU SEND recursive(9,1000)\ | asppanda | NORMAL | 2021-09-28T01:28:01.111542+00:00 | 2021-09-28T01:28:01.111587+00:00 | 1,005 | false | SUPPOSE YOU HAVE [9,6,9] AND SEESIONTIME=14\nSO U CAN MAKE A BITMASK 000\nWHEN YOU TAKE 9 BIT MASK BECOMES 1000 AS 9 IS LESS THAN 14 YOU SEND recursive(9,1000)\nthen you got 6 adding 6+9 you get 15 so u send 1+recursive(6,110)\nnow you have 9+6 you get 15 so u have greater than 14 so you send recursive(9,111)\nas you b... | 4 | 0 | ['Dynamic Programming', 'Backtracking', 'Bitmask', 'Java'] | 1 |
minimum-number-of-work-sessions-to-finish-the-tasks | C++ | Simple Backtracking | c-simple-backtracking-by-thangaraj1992-wu6x | Algorithm\nBacktracking:\nFor each task, we have two option\n1. To accomodate this task in one of the earlier sessions, given that earlier session time + cur_ta | Thangaraj1992 | NORMAL | 2021-08-29T09:19:35.657410+00:00 | 2021-08-29T09:19:35.657495+00:00 | 274 | false | **Algorithm**\nBacktracking:\nFor each task, we have two option\n1. To accomodate this task in one of the earlier sessions, given that earlier session time + cur_task_time <= max session time.\n2. To create a new session and allocate this task to that session.\n\nWe optimise the backtrack by breaking the recursion if o... | 4 | 0 | [] | 1 |
minimum-number-of-work-sessions-to-finish-the-tasks | c++ solution with explanation backtrack/dfs type. | c-solution-with-explanation-backtrackdfs-58t0 | As we are checking for all positions/arrangements of a task to be done hence it always give min answer. Any doubt ask in comment else if you like? upvote.\n\ncl | abaddu_21 | NORMAL | 2021-08-29T04:26:57.818232+00:00 | 2021-08-29T04:34:51.525447+00:00 | 545 | false | As we are checking for all positions/arrangements of a task to be done hence it always give min answer. Any doubt ask in comment else if you like? upvote.\n```\nclass Solution {\npublic:\n int ans; //stores answer\n void help(vector<int>& tasks,int idx,vector<int>& v,int Time)\n {\n if(v.size()>=ans) /... | 4 | 0 | ['Backtracking', 'C'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | ✅✅Easy To Understand || C++ Code | easy-to-understand-c-code-by-__kr_shanu_-e3ne | Using Recursion && Memoization\n\n\nclass Solution {\npublic:\n \n // declare a dp\n \n unordered_map<string, int> dp;\n \n // sessions will s | __KR_SHANU_IITG | NORMAL | 2022-09-02T06:59:46.372963+00:00 | 2022-09-02T06:59:46.373002+00:00 | 1,824 | false | * ***Using Recursion && Memoization***\n\n```\nclass Solution {\npublic:\n \n // declare a dp\n \n unordered_map<string, int> dp;\n \n // sessions will store the no. of active sessions\n \n vector<int> sessions;\n \n // function for creating key\n \n // we are sorting the arr to avoi... | 3 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'C', 'C++'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | [C++] Simple C++ Code | c-simple-c-code-by-prosenjitkundu760-bxu1 | \n\n# If you like the implementation then Please help me by increasing my reputation. By clicking the up arrow on the left of my image.\n\nclass Solution {\n | _pros_ | NORMAL | 2022-08-16T14:55:35.115942+00:00 | 2022-08-16T14:55:35.115983+00:00 | 821 | false | \n\n# **If you like the implementation then Please help me by increasing my reputation. By clicking the up arrow on the left of my image.**\n```\nclass Solution {\n int n;\n int dfs(int ctime, vector<vector<int>> &dp, vector<int>& tasks, int stime, int bitmask)\n {\n if(bitmask == (1<<n)-1)\n ... | 3 | 0 | ['Dynamic Programming', 'Backtracking', 'C', 'Bitmask', 'C++'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | DP + Bitmasking | CPH | dp-bitmasking-cph-by-dy-123-f61q | Page no. 103 of https://cses.fi/book/book.pdf read from Permutations to subsets. \n\n\nclass Solution {\npublic:\n int minSessions(vector<int>& tasks, int t | dy-123 | NORMAL | 2021-08-31T16:07:30.401910+00:00 | 2021-08-31T16:14:10.819555+00:00 | 196 | false | Page no. 103 of https://cses.fi/book/book.pdf read from Permutations to subsets. \n\n```\nclass Solution {\npublic:\n int minSessions(vector<int>& tasks, int t) {\n int n=tasks.size();\n vector<pair<int,int>>best(1<<n,{n+1,t+1});\n // best[0]={1,0};\n best[0]={0,t+1};\n for(int i=... | 3 | 0 | ['C'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | Java Solution | Backtrack + Recursion + Memoization | java-solution-backtrack-recursion-memoiz-smn1 | Solution:\n\n\nArrayList<Integer> sessions;\nHashMap<Pair<ArrayList<Integer>, Integer>,Integer> memo;\n\npublic int minSessions(int[] tasks, int sessionTime) {\ | gumptious33 | NORMAL | 2021-08-29T16:19:38.394887+00:00 | 2021-08-29T16:20:22.429742+00:00 | 786 | false | Solution:\n\n```\nArrayList<Integer> sessions;\nHashMap<Pair<ArrayList<Integer>, Integer>,Integer> memo;\n\npublic int minSessions(int[] tasks, int sessionTime) {\n\tsessions = new ArrayList();\n\tmemo = new HashMap();\n\treturn recursive(tasks, sessionTime, 0);\n}\n\nprivate int recursive(int[] tasks, int sessionTime,... | 3 | 1 | ['Backtracking', 'Recursion', 'Memoization', 'Java'] | 1 |
minimum-number-of-work-sessions-to-finish-the-tasks | [Java] 1-ms Optimize backtracking solution using 3 techniques | java-1-ms-optimize-backtracking-solution-wpb7 | While trying my backtracking solution, I was getting TLE. The optimizations that helped me are shown below:\n\n1. Sort task array in descending order which help | chemEn | NORMAL | 2021-08-29T05:19:22.242583+00:00 | 2021-08-29T09:30:31.190299+00:00 | 874 | false | While trying my backtracking solution, I was getting TLE. The optimizations that helped me are shown below:\n\n1. Sort task array in descending order which helps in determining minimum number of sessions in less iterations.\n\n2. Create a global variable that stores the minimum number of sessions possible at any time. ... | 3 | 0 | ['Backtracking', 'Java'] | 1 |
minimum-number-of-work-sessions-to-finish-the-tasks | (DP + bit masking) Similar to travelling salesman problem with slight modification | dp-bit-masking-similar-to-travelling-sal-g1t7 | This problem can be easily solved using dynamic programming and bitmasking\n\nHere, the ith bit in mask is 1 if the ith task has been completed otherwise it is | hemantkr79 | NORMAL | 2021-08-29T04:24:18.974357+00:00 | 2021-08-29T05:08:09.874070+00:00 | 292 | false | This problem can be easily solved using dynamic programming and bitmasking\n\nHere, the ith bit in mask is 1 if the ith task has been completed otherwise it is 0\nwhen all the tasks are done, the value of mask will be equal to the value of \'done\'\n\n```\nclass Solution {\npublic:\n int solve(vector<int> &tasks,in... | 3 | 0 | [] | 3 |
minimum-number-of-work-sessions-to-finish-the-tasks | AC by lucky | ac-by-lucky-by-liketheflower-owxr | As the task length is pretty small, if we random shuffle a large number of times, we will have a high possibility to find the optimal result. The solution is si | liketheflower | NORMAL | 2021-08-29T04:24:12.263877+00:00 | 2021-08-29T04:31:39.825572+00:00 | 128 | false | As the task length is pretty small, if we random shuffle a large number of times, we will have a high possibility to find the optimal result. The solution is simple:\nRandom shuffle N times and find the minimum result.\n\nI guess the test cases are not that strong, so I can get the code AC by lucky.\n\n```python\nclass... | 3 | 0 | [] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | C++ Implementation using DP with Bitmasking | c-implementation-using-dp-with-bitmaskin-3p5f | \n\n# Code\n\nclass Solution {\npublic:\n int dp[16385][16];\n int f(int mask,vector<int>& tasks, int sessionTime,int curr=0){\n if(mask==((1<<task | ayushnautiyal1110 | NORMAL | 2023-10-27T14:30:47.439780+00:00 | 2023-10-27T14:30:47.439809+00:00 | 65 | false | \n\n# Code\n```\nclass Solution {\npublic:\n int dp[16385][16];\n int f(int mask,vector<int>& tasks, int sessionTime,int curr=0){\n if(mask==((1<<tasks.size()) - 1)){\n return 1;\n }\n if(dp[mask][curr]!=-1){\n return dp[mask][curr];\n }\n int ans=1e9;\n ... | 2 | 0 | ['Dynamic Programming', 'Bit Manipulation', 'Bitmask', 'C++'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | Golang subset traversal problem | golang-subset-traversal-problem-by-frank-ug1r | Intuition\n\u8FD9\u79CD\u5C5E\u4E8E\u904D\u5386\u5B50\u96C6\u7684\u95EE\u9898 \u6709\u56FA\u5B9A\u7684\u89E3\u6CD5\n# Complexity\n- Time complexity: O(3^n)\n Ad | franklinwen | NORMAL | 2022-12-22T00:50:12.409250+00:00 | 2022-12-22T00:50:12.409287+00:00 | 110 | false | # Intuition\n\u8FD9\u79CD\u5C5E\u4E8E\u904D\u5386\u5B50\u96C6\u7684\u95EE\u9898 \u6709\u56FA\u5B9A\u7684\u89E3\u6CD5\n# Complexity\n- Time complexity: O(3^n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(2^n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nfunc ... | 2 | 0 | ['Go'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | C++ || Fully Detailed Intuitions Explained ||No DP || Binary Search + Backtracking || Clean code | c-fully-detailed-intuitions-explained-no-ksg2 | Intuition -> We want to divide into minimum no of partitions such that all the tasks gets finished.\n\n## What we are looking to implement is , max size of part | KR_SK_01_In | NORMAL | 2022-08-18T13:47:30.223489+00:00 | 2022-08-18T14:00:39.869527+00:00 | 1,238 | false | ## Intuition -> We want to divide into minimum no of partitions such that all the tasks gets finished.\n\n## What we are looking to implement is , max size of partitions of time can be at max n & min will be 1.\n\n## So we will apply binary search on that, mid will be the our current no. of partitions we taken , we wil... | 2 | 0 | ['Backtracking', 'C', 'Binary Tree', 'C++'] | 1 |
minimum-number-of-work-sessions-to-finish-the-tasks | C++ || DP + Bitmasking | c-dp-bitmasking-by-rosario1975-655u | class Solution {\npublic:\n \n vector> dp;\n \n int fun(int curTime,vector& arr,int t,int mask){\n if(mask == (1 << arr.size())-1)\n | rosario1975 | NORMAL | 2022-07-10T21:40:52.255987+00:00 | 2022-07-10T21:40:52.256031+00:00 | 356 | false | class Solution {\npublic:\n \n vector<vector<int>> dp;\n \n int fun(int curTime,vector<int>& arr,int t,int mask){\n if(mask == (1 << arr.size())-1)\n return 0;\n \n if(dp[curTime][mask] != -1)\n return dp[curTime][mask];\n \n \n int ans = 15;\n... | 2 | 0 | ['Dynamic Programming', 'Bit Manipulation', 'C', 'C++'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | Python Backtracking /w pruning | python-backtracking-w-pruning-by-hszh-nvtg | \nclass Solution:\n def minSessions(self, tasks: List[int], sessionTime: int) -> int:\n \n sessions = []\n \n self.ans = n = len( | hsZh | NORMAL | 2022-06-18T16:55:12.247224+00:00 | 2022-06-18T16:55:12.247259+00:00 | 230 | false | ```\nclass Solution:\n def minSessions(self, tasks: List[int], sessionTime: int) -> int:\n \n sessions = []\n \n self.ans = n = len(tasks)\n \n def backtracking(i):\n \n # pruning\n if len(sessions) >= self.ans:\n return\n ... | 2 | 0 | [] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | O(n!logn) 0 ms 100% Faster Binary Search + Recursion C++ Solution | onlogn-0-ms-100-faster-binary-search-rec-9u6h | Problems for Idea Reference: https://leetcode.com/problems/partition-to-k-equal-sum-subsets/\n2. Book Alloction Problem (similiar to this https://leetcode.com/p | shubhamjha386 | NORMAL | 2022-04-29T07:01:38.526234+00:00 | 2022-06-05T10:26:45.129969+00:00 | 480 | false | Problems for Idea Reference: https://leetcode.com/problems/partition-to-k-equal-sum-subsets/\n2. Book Alloction Problem (similiar to this https://leetcode.com/problems/split-array-largest-sum/)\n\nSolution\n```\nclass Solution {\npublic:\n bool solve(vector<int> &nums,int &target,int idx,vector<int>&map)\n {\n ... | 2 | 0 | ['Backtracking', 'Recursion', 'Binary Tree'] | 4 |
minimum-number-of-work-sessions-to-finish-the-tasks | [Java] share my simple DFS backtracking solution with pruning, beats 91% | java-share-my-simple-dfs-backtracking-so-h896 | \n\nclass Solution {\n int min;\n public int minSessions(int[] tasks, int sessionTime) {\n min = tasks.length + 1; // upper bound, any result can\' | timmybeeflin | NORMAL | 2022-01-16T10:33:19.661536+00:00 | 2022-01-16T10:33:19.661563+00:00 | 797 | false | \n```\nclass Solution {\n int min;\n public int minSessions(int[] tasks, int sessionTime) {\n min = tasks.length + 1; // upper bound, any result can\'t over this upper bound\n \n Arrays.sort(tasks);\n reverse(tasks);\n dfs(tasks, 0, new int[tasks.length], sessionTime, 0);\n ... | 2 | 0 | ['Backtracking', 'Depth-First Search', 'Java'] | 1 |
minimum-number-of-work-sessions-to-finish-the-tasks | Solved without skills | solved-without-skills-by-imironhead-jnto | Honestly, I solved it by adding more and more conditions.\n\nThe basic idea is to check if N sessions are enough and do binary search on N.\n\nSome optimization | imironhead | NORMAL | 2021-09-05T18:19:45.040932+00:00 | 2021-09-05T18:19:45.040962+00:00 | 716 | false | Honestly, I solved it by adding more and more conditions.\n\nThe basic idea is to check if `N` sessions are enough and do binary search on `N`.\n\nSome optimizations are:\n- Sorts tasks. Processing heavy tasks first result in early rejections.\n- The minimum possible \'N\' is `max(1, sum(tasks) // sessionTime)`.\n- If ... | 2 | 0 | ['Binary Search', 'Python'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | Example why sorting and greedy is not enough | example-why-sorting-and-greedy-is-not-en-zun9 | I see some examples like tasks = {3, 4, 7, 8, 10} sessionTime = 12, But sorting and greedy can give correct answer for that one. I manage to find on that greedy | fdsm_lhn | NORMAL | 2021-09-04T00:27:57.129128+00:00 | 2021-09-04T00:27:57.129160+00:00 | 658 | false | I see some examples like `tasks` = {3, 4, 7, 8, 10} `sessionTime` = 12, But sorting and greedy can give correct answer for that one. I manage to find on that greedy is not working right.\n\nthinking of case like `tasks` = {16, 9, 8, 7,6,6,3,2,2,1} `sessionTime` = 20,after first 6 tasks, u should have three session with... | 2 | 0 | [] | 1 |
minimum-number-of-work-sessions-to-finish-the-tasks | c++ dp solution using mask | c-dp-solution-using-mask-by-dilipsuthar6-lpvq | \nclass Solution {\npublic:\n long long dp[1<<15][180];\n int find(vector<int>&nums,int mask,int sum,int se,int n)\n {\n if(mask==(1<<n)-1)\n | dilipsuthar17 | NORMAL | 2021-08-30T15:26:00.994004+00:00 | 2021-08-30T15:26:00.994043+00:00 | 259 | false | ```\nclass Solution {\npublic:\n long long dp[1<<15][180];\n int find(vector<int>&nums,int mask,int sum,int se,int n)\n {\n if(mask==(1<<n)-1)\n {\n return 1;\n }\n int ans=INT_MAX;\n if(dp[mask][sum]!=-1)\n {\n return dp[mask][sum];\n }\n ... | 2 | 0 | ['C', 'Bitmask', 'C++'] | 1 |
minimum-number-of-work-sessions-to-finish-the-tasks | [Python] recursion + tuple memoization, no bitmask, simple 64ms | python-recursion-tuple-memoization-no-bi-tske | I thought some of the other python recursion answers were not that intuitive. Here we simply try each possibility and cache what we\'ve done so far so no repeti | rjmcmc | NORMAL | 2021-08-29T19:27:53.457277+00:00 | 2021-08-29T19:34:08.294721+00:00 | 601 | false | I thought some of the other python recursion answers were not that intuitive. Here we simply try each possibility and cache what we\'ve done so far so no repetition. We take advantage of the tuple data structure which can be cached. The parameter x represents remaining sessiontime for this session. We reset it (plus ad... | 2 | 0 | ['Recursion', 'Memoization', 'Python3'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | [Python3] bit-mask dp | python3-bit-mask-dp-by-ye15-2cxc | Please see this commit for solutions of weekly 256.\n\n\nclass Solution:\n def minSessions(self, tasks: List[int], sessionTime: int) -> int:\n \n | ye15 | NORMAL | 2021-08-29T17:06:03.423179+00:00 | 2021-08-30T04:23:14.708683+00:00 | 418 | false | Please see this [commit](https://github.com/gaosanyong/leetcode/commit/7abfd85d1a68e375fcc0be60558909fd98b270f3) for solutions of weekly 256.\n\n```\nclass Solution:\n def minSessions(self, tasks: List[int], sessionTime: int) -> int:\n \n @cache\n def fn(mask, rem):\n """Return minimu... | 2 | 0 | ['Python3'] | 3 |
minimum-number-of-work-sessions-to-finish-the-tasks | Ruby/C# - Recursive solution | rubyc-recursive-solution-by-shhavel-24m3 | Solution\n\nAdd two arguments to the function: \n time - remainning time in the current session;\n spent - number of sessions already worked.\n \n# Explanation\ | shhavel | NORMAL | 2021-08-29T10:41:14.129143+00:00 | 2021-08-31T08:15:11.627782+00:00 | 176 | false | # Solution\n\nAdd two arguments to the function: \n `time` - remainning time in the current session;\n `spent` - number of sessions already worked.\n \n# Explanation\n\nCheck all tasks that can feet in remaining `time` and choose minimum posible value recursivelly \nor just start a new session if none feet (in remainin... | 2 | 0 | ['Recursion', 'Ruby'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | Java Bitmask | java-bitmask-by-ziwang0411-zzf1 | use bitmask to represent current works done. \nfor example, if current state = 101111 means second job is not done. \nTherefore, for the next state (111111), jo | ziwang0411 | NORMAL | 2021-08-29T04:24:10.004710+00:00 | 2021-08-29T04:24:10.004737+00:00 | 233 | false | use bitmask to represent current works done. \nfor example, if current state = 101111 means second job is not done. \nTherefore, for the next state (111111), job 2 is done and you will have :\n1. dp[111111][session+job2Time] = min(dp[111111][session+job2Time], dp[101111][session]) for currentJobsInTheSession+job2Time i... | 2 | 0 | [] | 2 |
minimum-number-of-work-sessions-to-finish-the-tasks | C++ | Explanation (Recursion + Memo + Bitmask) | c-explanation-recursion-memo-bitmask-by-5vls3 | We will keep adding to current untill task[pos]+cur <=SessionTime, ans remains same since we are not starting new session.\nIf cur+task[pos]>SessionTime, then w | codingsuju | NORMAL | 2021-08-29T04:13:34.032836+00:00 | 2021-08-29T05:18:15.430405+00:00 | 260 | false | We will keep adding to current untill task[pos]+cur <=SessionTime, ans remains same since we are not starting new session.\nIf cur+task[pos]>SessionTime, then we will start new session,and add 1 to ans since we are starting new session.\nEverytime we start new session , we should add 1 to ans.\n\nHere, in dp[mask][cur]... | 2 | 0 | ['Dynamic Programming', 'Recursion', 'Bitmask'] | 2 |
minimum-number-of-work-sessions-to-finish-the-tasks | Python | Self-Inspired | Only work on Leetcode testcases. | python-self-inspired-only-work-on-leetco-659n | \nfrom itertools import combinations\nclass Solution:\n def minSessions(self, tasks: List[int], sessionTime: int) -> int:\n \n tasks.sort()\n | yichonggoh99 | NORMAL | 2021-08-29T04:01:41.582923+00:00 | 2021-08-29T08:11:24.791544+00:00 | 523 | false | ```\nfrom itertools import combinations\nclass Solution:\n def minSessions(self, tasks: List[int], sessionTime: int) -> int:\n \n tasks.sort()\n \n ans = 0\n i=1\n \n while tasks and i<=len(tasks): #get rid of all possible combination that results in sessionTime\n ... | 2 | 0 | [] | 1 |
minimum-number-of-work-sessions-to-finish-the-tasks | Simple Solution | simple-solution-by-shlok1913-ir4z | Code | shlok1913 | NORMAL | 2025-04-10T11:06:30.526812+00:00 | 2025-04-10T11:06:30.526812+00:00 | 8 | false | # Code
```cpp []
class Solution {
public:
// map<pair <set <int> , int> , int> mp;
// i have to do bitmasking
// to chech if some bit in a number is 0 or not
// (num >> k) & 1 => 1/0
// to set some kth to one use this formulae
// num |= (1 << k)
// you can unset the bit using num &= ~(1 << k);
// and for the base ca... | 1 | 0 | ['Dynamic Programming', 'Backtracking', 'Bit Manipulation', 'C++'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | Straightforward Bitmask DP soln || Commented Solution | straightforward-bitmask-dp-soln-commente-7k2y | The approach is explained in the code.Code | Satyamjha_369 | NORMAL | 2025-02-05T18:31:47.612116+00:00 | 2025-02-05T18:31:47.612116+00:00 | 78 | false | The approach is explained in the code.
# Code
```cpp []
class Solution {
public:
int solve(vector<int>& t, int k, vector<vector<int>>& dp, int mask, int time){
if(mask == (1 << t.size()) - 1) //when completed all tasks
return 0;
if(dp[mask][time] != -1) //if subproblem solved be... | 1 | 0 | ['C++'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | C++ Easy To Read Memo Bitmask | c-easy-to-read-memo-bitmask-by-tristan23-ew3g | Code | Tristan232 | NORMAL | 2025-02-04T06:35:57.860087+00:00 | 2025-02-04T06:35:57.860087+00:00 | 55 | false |
# Code
```cpp []
class Solution {
public:
int set = 0;
int recur(vector<int>& tasks, int mask, int session, vector<vector<int>>& dp) {
if (mask==pow(2,tasks.size())-1) {
return 0;
}
if (dp[mask][session]!=-1) {
return dp[mask][session];
}
int r... | 1 | 0 | ['Array', 'Dynamic Programming', 'Backtracking', 'Bit Manipulation', 'Bitmask', 'C++'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | Binary Search & Backtracking | 100% | binary-search-backtracking-100-by-rockwe-26y0 | IntuitionSince the goal is to minimize work sessions lets binary search the number of sessions possible. So a basic binary search with the conditional being can | rockwell153 | NORMAL | 2025-02-03T18:12:47.337414+00:00 | 2025-02-03T18:35:39.397951+00:00 | 60 | false | # Intuition
Since the goal is to minimize work sessions lets binary search the number of sessions possible. So a basic binary search with the conditional being `canPartition`, where `canPartition` simply tries to fit all tasks into `mid` number of work sessions.
# Complexity
- Time complexity:
O( logn * k^n )
- Space... | 1 | 0 | ['Binary Search', 'Backtracking', 'C++'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | Bitmask dp | bitmask-dp-by-leofu-qds5 | 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 | leofu | NORMAL | 2024-10-11T10:35:11.204262+00:00 | 2024-10-11T11:54:31.672054+00:00 | 100 | 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 | ['C++'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | Very Simple Solution || Easy to understand | very-simple-solution-easy-to-understand-v9bwi | Complexity\n- Time complexity: O(2^n)\n\n- Space complexity: O(n)\n\n# Code\n\nclass Solution {\n void solve(int i, vector<int>& tasks, vector<int>& session, | coder_rastogi_21 | NORMAL | 2024-03-09T05:35:23.823084+00:00 | 2024-03-09T05:35:23.823119+00:00 | 81 | false | # Complexity\n- Time complexity: $$O(2^n)$$\n\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass Solution {\n void solve(int i, vector<int>& tasks, vector<int>& session, int sessionTime, int &ans)\n {\n if(i == tasks.size()) { //base case\n ans = min(ans,int(session.size())); //update the minimum ... | 1 | 0 | ['Backtracking', 'C++'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | Python | DFS + Binary Search | ❌bitmask❌DP | Faster than 99% | python-dfs-binary-search-bitmaskdp-faste-vj2l | Intuition\n Describe your first thoughts on how to solve this problem. \nJust don\'t want to use bitmask and dynamic programming.\n# Approach\n Describe your ap | randaldong | NORMAL | 2022-11-18T08:42:40.575550+00:00 | 2022-11-18T08:42:58.465343+00:00 | 299 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nJust don\'t want to use bitmask and dynamic programming.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- How to find the minimum number of sessions? We can use binary search to do this. But different from typical b... | 1 | 0 | ['Binary Search', 'Depth-First Search', 'Python3'] | 1 |
minimum-number-of-work-sessions-to-finish-the-tasks | Java | Space O(2^n) | Bottom-Up 1D DP | java-space-o2n-bottom-up-1d-dp-by-studen-y4nb | Saw a lot of the posts on the front most-upvoted page with 2D dp with space complexity O(2^n * W). It\'s unnecssary. We can do it in O(2^n) space.\nBecause, for | Student2091 | NORMAL | 2022-07-30T23:27:24.195204+00:00 | 2022-07-30T23:40:58.039963+00:00 | 748 | false | Saw a lot of the posts on the front most-upvoted page with 2D dp with space complexity `O(2^n * W)`. It\'s unnecssary. We can do it in `O(2^n)` space.\nBecause, for a given subset of tasks, there is only 1 optimal way - the minimum number of bin required and then followed by the minimum weight.\nThere is no reason to t... | 1 | 0 | ['Dynamic Programming', 'Bitmask', 'Java'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | c++ | Backtraking Without DP and BitMasking 94% Faster | c-backtraking-without-dp-and-bitmasking-u4zbv | \nclass Solution {\npublic:\n int minSize = INT_MAX;\n void minHelper(vector<int> tasks,int time,int index,vector<int> assign){\n if(assign.size()> | bhagwat_singh_cse | NORMAL | 2022-07-13T04:25:40.423159+00:00 | 2022-07-13T04:25:40.423211+00:00 | 337 | false | ```\nclass Solution {\npublic:\n int minSize = INT_MAX;\n void minHelper(vector<int> tasks,int time,int index,vector<int> assign){\n if(assign.size()>=minSize)return;\n \n if(index==tasks.size()){\n int size = assign.size();\n minSize = size<minSize?size:minSize;\n ... | 1 | 0 | ['Backtracking', 'Recursion'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | 1986. Minimum Sessions ( c++ Dp with Bitmask using pairs) | 1986-minimum-sessions-c-dp-with-bitmask-86t4r | \ntypedef pair<int,int> pi;\nclass Solution {\npublic:\n int minSessions(vector<int>& tasks, int sessionTime) {\n int n=tasks.size();\n pi mask | 012_amar | NORMAL | 2022-06-25T13:01:55.959013+00:00 | 2022-06-25T13:01:55.959044+00:00 | 91 | false | ```\ntypedef pair<int,int> pi;\nclass Solution {\npublic:\n int minSessions(vector<int>& tasks, int sessionTime) {\n int n=tasks.size();\n pi masks[1<<n];\n masks[0]=make_pair(1,0);\n for(int i=1;i<1<<n;i++){\n masks[i]=pi{n+1,0};\n for(int j=0;j<n;j++){\n ... | 1 | 0 | [] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.