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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
minimum-number-of-work-sessions-to-finish-the-tasks | C++ || DP || Top Down | c-dp-top-down-by-rajat0301tajar-4btp | \nclass Solution {\npublic:\n typedef long long int64;\n int64 dp[1 << 15][16];\n int threshold;\n int64 solve(vector<int> &t, int mask, int currTim | rajat0301tajar | NORMAL | 2022-04-23T16:58:05.409728+00:00 | 2022-04-23T16:58:05.409756+00:00 | 332 | false | ```\nclass Solution {\npublic:\n typedef long long int64;\n int64 dp[1 << 15][16];\n int threshold;\n int64 solve(vector<int> &t, int mask, int currTime) {\n int n = t.size();\n if(mask == ((1 << n) - 1)) {\n return 1;\n }\n if(dp[mask][currTime] != -1) {\n ... | 1 | 0 | [] | 1 |
minimum-number-of-work-sessions-to-finish-the-tasks | sinkineben | C++ | Binary Search | State compression DP | sinkineben-c-binary-search-state-compres-1ka5 | Analysis\n\nWe should put the tasks into n boxes, the size of each box is sessionTime. And we want to minimize such n.\n\n\n\n## Binary Search\n\n- The min numb | sinkinben | NORMAL | 2022-04-07T12:43:14.673712+00:00 | 2022-04-07T12:43:14.673740+00:00 | 285 | false | **Analysis**\n\nWe should put the `tasks` into `n` boxes, the size of each box is `sessionTime`. And we want to minimize such `n`.\n\n\n\n## Binary Search\n\n- The min number of sessions we need is `l = SUM(tasks) / sessionTime`.\n- The max number of session we need is `n = tasks.size`.\n- Perform a binary search on th... | 1 | 0 | ['Dynamic Programming', 'C'] | 1 |
minimum-number-of-work-sessions-to-finish-the-tasks | C++ | Backtracking with pruning | Beats 95% | c-backtracking-with-pruning-beats-95-by-rk4a3 | ```\nclass Solution {\nprivate:\n void backtrack(vector&tasks,vector&sessionTimes,int &ans,int index,int sessTime){\n if(sessionTimes.size()>=ans){\n | Diavolos | NORMAL | 2022-01-31T05:45:43.413448+00:00 | 2022-01-31T05:47:13.998140+00:00 | 557 | false | ```\nclass Solution {\nprivate:\n void backtrack(vector<int>&tasks,vector<int>&sessionTimes,int &ans,int index,int sessTime){\n if(sessionTimes.size()>=ans){\n return;\n } else if(index>=tasks.size()){\n ans=min(ans,(int)sessionTimes.size());\n } else {\n for(int i=0;i<sessionTimes.size... | 1 | 0 | ['Backtracking', 'C', 'C++'] | 2 |
minimum-number-of-work-sessions-to-finish-the-tasks | C++ Solution | Backtracking | Clean and Concise | c-solution-backtracking-clean-and-concis-sgs8 | \nclass Solution {\npublic:\n int mini;\n void backtrack(vector<int> tasks,int index,int st,int size,vector<int> count)\n {\n if(count.size()>mi | 1905759 | NORMAL | 2022-01-10T06:27:36.933131+00:00 | 2022-01-10T06:27:36.933177+00:00 | 231 | false | ```\nclass Solution {\npublic:\n int mini;\n void backtrack(vector<int> tasks,int index,int st,int size,vector<int> count)\n {\n if(count.size()>mini)\n return;\n if(index==size)\n {\n mini=min(mini,(int)count.size() );\n return;\n }\n int sum... | 1 | 0 | [] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | [C++] || Recursion + Memoization With BitMasking || ✅ | c-recursion-memoization-with-bitmasking-zux2m | \nclass Solution {\npublic:\n int n;\n vector<int> tasks;\n int sessionTime;\n\n int bitMask; //the standard BitMask\n \n vector<vector<int>> | tbne1905 | NORMAL | 2022-01-06T04:10:47.320986+00:00 | 2022-01-06T04:11:28.502250+00:00 | 161 | false | ```\nclass Solution {\npublic:\n int n;\n vector<int> tasks;\n int sessionTime;\n\n int bitMask; //the standard BitMask\n \n vector<vector<int>> f; // the memoization matrix \n\n int memo(int taskNo, int timeRemain){\n /*\n - taskNo: of all the remaining tasks, which task must be don... | 1 | 0 | [] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | c# : Easy Solution | c-easy-solution-by-rahul89798-vv6q | \tpublic class Solution\n\t{\n\t\tpublic int MinSessions(int[] tasks, int sessionTime)\n\t\t{\n\t\t\tint[,] dp = new int[(1 << tasks.Length), sessionTime + 1];\ | rahul89798 | NORMAL | 2021-12-13T14:05:28.700581+00:00 | 2021-12-13T14:05:28.700607+00:00 | 184 | false | \tpublic class Solution\n\t{\n\t\tpublic int MinSessions(int[] tasks, int sessionTime)\n\t\t{\n\t\t\tint[,] dp = new int[(1 << tasks.Length), sessionTime + 1];\n\t\t\treturn Solve(tasks, sessionTime, dp, 0, 0);\n\t\t}\n\n\t\tpublic int Solve(int[] tasks, int sessionTime, int[,] dp, int taken, int currTime)\n\t\t{\n\t\t... | 1 | 0 | ['Backtracking', 'Bit Manipulation', 'Bitmask'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | [Py3/Py] Simple solution w/ comments | py3py-simple-solution-w-comments-by-sssh-90um | NOTE: Use cache instead of lru_cache for memoization\n> \n\n\n\nfrom math import inf\nfrom functools import cache\n\nclass Solution:\n def minSessions(self, | ssshukla26 | NORMAL | 2021-11-21T00:08:57.439441+00:00 | 2021-11-21T00:10:38.369296+00:00 | 271 | false | > NOTE: Use cache instead of lru_cache for memoization\n> \n\n\n```\nfrom math import inf\nfrom functools import cache\n\nclass Solution:\n def minSessions(self, tasks: List[int], sessionTime: int) -> int:\n \n # Init\n n = len(tasks)\n \n @cache # NOTE: here use cache instead of l... | 1 | 1 | ['Dynamic Programming', 'Bit Manipulation'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | simple C++ using dp | simple-c-using-dp-by-luoyuf-1ido | \nint minSessions_(int idx, int mask, int left, vector<int>& tasks, int sessionTime, vector<vector<int>>& dp) {\n \n if (mask == ((1 << tasks.size()) - 1) | luoyuf | NORMAL | 2021-11-04T17:56:02.562985+00:00 | 2021-11-04T17:56:02.563022+00:00 | 311 | false | ```\nint minSessions_(int idx, int mask, int left, vector<int>& tasks, int sessionTime, vector<vector<int>>& dp) {\n \n if (mask == ((1 << tasks.size()) - 1))\n return 0;\n \n if (dp[left][mask] < INT_MAX) return dp[left][mask];\n \n int tot = INT_MAX;\n \n for (int i = 0; i < tasks.size(... | 1 | 0 | [] | 1 |
minimum-number-of-work-sessions-to-finish-the-tasks | Python backtracking about 280ms and very low space complexity | python-backtracking-about-280ms-and-very-l6vw | This was directly inspired by this solution: https://leetcode.com/problems/minimum-number-of-work-sessions-to-finish-the-tasks/discuss/1433054/Python-or-Backtr | shabie | NORMAL | 2021-10-23T18:41:37.399953+00:00 | 2021-11-06T22:20:43.282250+00:00 | 813 | false | This was directly inspired by this solution: https://leetcode.com/problems/minimum-number-of-work-sessions-to-finish-the-tasks/discuss/1433054/Python-or-Backtracking-or-664ms-or-100-time-and-space-or-Explanation\n\nBasically the idea is to formulate it as a problem of finding least number of sessions such that their s... | 1 | 0 | ['Backtracking', 'Python', 'Python3'] | 1 |
minimum-number-of-work-sessions-to-finish-the-tasks | C++ backtracking + dp | c-backtracking-dp-by-rohanjainbits-u6n8 | \nclass Solution {\npublic:\n \n int minSes(int session,long long int completedTasks,vector<int>& tasks,int sessionTime,vector<vector<int>>& dp)\n {\n | rohanjainbits | NORMAL | 2021-10-12T10:33:58.603753+00:00 | 2021-10-12T10:33:58.603788+00:00 | 280 | false | ```\nclass Solution {\npublic:\n \n int minSes(int session,long long int completedTasks,vector<int>& tasks,int sessionTime,vector<vector<int>>& dp)\n {\n int n = tasks.size();\n \n if(completedTasks==(pow(2,n)-1))\n {\n return dp[session][completedTasks]=1;\n }\n ... | 1 | 0 | [] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | [C++] DP with Bitmask | c-dp-with-bitmask-by-amsv_24-v2pa | \nclass Solution {\npublic:\n int dp[1<<14+1][16];\n int solve(vector<int>&tasks, int n, int mask, int time, int t){\n if(time>t)\n retu | amsv_24 | NORMAL | 2021-09-01T12:34:55.297816+00:00 | 2021-09-01T12:34:55.297845+00:00 | 370 | false | ```\nclass Solution {\npublic:\n int dp[1<<14+1][16];\n int solve(vector<int>&tasks, int n, int mask, int time, int t){\n if(time>t)\n return INT_MAX;\n if(mask==0)\n return 1;\n if(dp[mask][time]!=-1)\n return dp[mask][time];\n \n //for each tas... | 1 | 0 | ['Recursion', 'C', 'Bitmask', 'C++'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | C++ Short general code with O(3^n) | c-short-general-code-with-o3n-by-maximgo-1lyg | Create all possible subsets and keep assigning valid ones to sessions:\n\nclass Solution {\n // sumMap is for faster subSet sum lookup:\n int getSum(int m | maximgorkey | NORMAL | 2021-08-31T14:41:18.962847+00:00 | 2021-08-31T14:41:18.962891+00:00 | 115 | false | Create all possible subsets and keep assigning valid ones to sessions:\n```\nclass Solution {\n // sumMap is for faster subSet sum lookup:\n int getSum(int mask, const std::vector<int> &tasks, const int n)\n {\n int sum = 0;\n for(int i = 0; i < n && mask; ++i) {\n sum += (mask &1) ? t... | 1 | 0 | [] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | JAVA Binary Search 2ms Solution, same as Problem 1723. Find Minimum Time to Finish All Jobs | java-binary-search-2ms-solution-same-as-x7dbh | Minimum Number of Work Sessions to Finish the Tasks\n\n public int minSessions(int[] tasks, int sessionTime) {\n Arrays.sort(tasks);\n int lo = | chenzuojing | NORMAL | 2021-08-31T01:42:15.522373+00:00 | 2021-09-25T23:54:16.149686+00:00 | 165 | false | 1986. Minimum Number of Work Sessions to Finish the Tasks\n```\n public int minSessions(int[] tasks, int sessionTime) {\n Arrays.sort(tasks);\n int lo = 1, hi = tasks.length;\n\n while (lo < hi) {\n int numSessions = (lo + hi) / 2;\n if (canSchedule(tasks, new int[numSessio... | 1 | 0 | [] | 1 |
minimum-number-of-work-sessions-to-finish-the-tasks | C++ | Runtime- 0ms sometimes 4ms beats 100% | Size- 7.6 MB beats 100% | DP | Subset sum | | c-runtime-0ms-sometimes-4ms-beats-100-si-4mds | Time Complexity: O(s*n^2), s=sessionTime, n= tasks length\n\nLets take this example tasks=[2,3,4,4,5,6,7,10], sessionTime=12\n\nWe can store number of times an | lc_mb | NORMAL | 2021-08-30T15:28:36.198233+00:00 | 2021-08-30T15:28:36.198273+00:00 | 140 | false | **Time Complexity: O(s*n^2)**, s=sessionTime, n= tasks length\n\nLets take this example **tasks=[2,3,4,4,5,6,7,10], sessionTime=12**\n\nWe can store number of times an element is appearing in tasks, to a vector (like a hash map).\nLets create **hashVector=[0,0,1,1,2,1,1,1,0,0,1]** for elements 0 to 10 and initialise ou... | 1 | 0 | ['Dynamic Programming', 'C'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | Java - 1ms - bitmask & backtracking recursion - Easy recursive thinking | java-1ms-bitmask-backtracking-recursion-6ubr9 | Idea / Intuition\n I thought of having individual slots for each task as each of them is less than sessionTime, as that would be the requirement in worst case.\ | mystic13 | NORMAL | 2021-08-30T14:14:21.763442+00:00 | 2021-08-30T14:18:45.967898+00:00 | 386 | false | **Idea / Intuition**\n* I thought of having individual slots for each task as each of them is less than sessionTime, as that would be the requirement in worst case.\n* So for each new element we need to recur for an old slot with time>= current element time and one full empty slot.\n* To prune we can keep slotCount and... | 1 | 0 | ['Backtracking', 'Java'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | track all possible combinations of open slots | python3 | track-all-possible-combinations-of-open-a7st9 | Approach\n Keep track of all possible options which will contain slots of time to fit in a given task\n Start with one option of one slot of sessionTime \n For | 495 | NORMAL | 2021-08-30T02:07:31.182086+00:00 | 2021-08-30T02:08:48.892178+00:00 | 111 | false | ### Approach\n* Keep track of all possible options which will contain slots of time to fit in a given `task`\n* Start with one option of one slot of `sessionTime` \n* For each new `task`, we have two choices:\n\t* Fit the `task` in one of the open slots in one of the available options, creating more opitons of slots\n\... | 1 | 0 | [] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | Python Top-Down DP and Thinking Process | python-top-down-dp-and-thinking-process-2kdns | Inspired by this top voted post:\nhttps://leetcode.com/problems/minimum-number-of-work-sessions-to-finish-the-tasks/discuss/1432155/Easier-than-top-voted-ones-o | shangpochou | NORMAL | 2021-08-29T22:29:24.586648+00:00 | 2021-08-29T22:29:24.586677+00:00 | 102 | false | Inspired by this top voted post:\nhttps://leetcode.com/problems/minimum-number-of-work-sessions-to-finish-the-tasks/discuss/1432155/Easier-than-top-voted-ones-or-LegitClickbait-or-c%2B%2B\nWhich has a great explanation of how does bit masks works for this problem.\n\nThe brutal recursive solution is finding all possibl... | 1 | 0 | [] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | [python] walk bucket solution, easy to understand | python-walk-bucket-solution-easy-to-unde-6op4 | this problem is similar to problem 1723.\nthe solution is straightforward. there are n tasks, so we create n bucket. each task[i] will be placed to one of the b | zyj5353 | NORMAL | 2021-08-29T18:07:20.953550+00:00 | 2021-08-29T18:07:20.953618+00:00 | 137 | false | this problem is similar to problem 1723.\nthe solution is straightforward. there are n tasks, so we create n bucket. each task[i] will be placed to one of the bucket. the non-empty bucket is the number of sessions and we want to find the min.\nBelow is the code. \nfunction walk will walk through every task and try to p... | 1 | 0 | [] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | Knapsack-like | 0 ms | O(s*n^2) Worst Case | knapsack-like-0-ms-osn2-worst-case-by-in-mmuw | Step 1: Build DP Matrix\n\nBuild a knapsack-like matrix to find how many ways we can spend X time with our current tasks.\n\nEx. [1,2,3] sessionTime = 3\n\n0 | IndievdB | NORMAL | 2021-08-29T17:03:28.626603+00:00 | 2021-08-29T17:13:42.049362+00:00 | 237 | false | **Step 1: Build DP Matrix**\n\nBuild a knapsack-like matrix to find how many ways we can spend X time with our current tasks.\n\nEx. [1,2,3] sessionTime = 3\n\n**0 1 2 3** \n1 0 0 0 | *looking at 0 tasks*\n1 1 0 0 | *including task 1*\n1 1 1 1 | *including task 2*\n1 1 1 2 | *including task 3*\n\n#Ways to sp... | 1 | 0 | ['C', 'C++'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | JavaScript and TypeScript Bitmask DP | javascript-and-typescript-bitmask-dp-by-jxzaw | DP[mask][time] = Minimum number of work sessions after assigning task by mask and it remains time session time\n\nJavaScript\njs\n/**\n * @param {number[]} task | menheracapoo | NORMAL | 2021-08-29T14:39:09.007836+00:00 | 2021-08-30T14:15:40.346428+00:00 | 324 | false | DP[mask][time] = Minimum number of work sessions after assigning task by `mask` and it remains `time` session time\n\nJavaScript\n```js\n/**\n * @param {number[]} tasks\n * @param {number} sessionTime\n * @return {number}\n */\nvar minSessions = function(tasks, sessionTime) {\n const n = tasks.length;\n const dp = Ar... | 1 | 0 | ['TypeScript', 'JavaScript'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | [C++] DP+Bitmasking | c-dpbitmasking-by-sahil_rajput_2000-7iti | \n/*\n Kind of Problem where we have the option to Pick now or Pick later but we definatley have to pick all items.\n We are using dp with bitmasking here w | sahil_rajput_2000 | NORMAL | 2021-08-29T12:30:58.620999+00:00 | 2021-11-10T12:37:40.364183+00:00 | 126 | false | ```\n/*\n Kind of Problem where we have the option to Pick now or Pick later but we definatley have to pick all items.\n We are using dp with bitmasking here where a ith bit in mask represents that element isPicked or not.\n if 1 that means picked if 0 means not picked Yet.\n We will do memoization to save time... | 1 | 0 | [] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | clean dp with memoization | clean-dp-with-memoization-by-youngsam-hjfs | credit to @shourabhpayal\nfor c++ https://leetcode.com/problems/minimum-number-of-work-sessions-to-finish-the-tasks/discuss/1431836/C%2B%2B-Solution-or-Recursio | youngsam | NORMAL | 2021-08-29T09:49:58.856263+00:00 | 2021-08-29T09:49:58.856297+00:00 | 106 | false | credit to @shourabhpayal\nfor c++ https://leetcode.com/problems/minimum-number-of-work-sessions-to-finish-the-tasks/discuss/1431836/C%2B%2B-Solution-or-Recursion-%2B-Memoization\n\n\nidea\n1. use bit mask to represent array \n 1) for selected element, set ith index to 1\n 2) for unselected element, is ith index i... | 1 | 0 | [] | 1 |
minimum-number-of-work-sessions-to-finish-the-tasks | [C++] Dynamic Programming with bit-masking (commented) | c-dynamic-programming-with-bit-masking-c-ad0k | \nclass Solution\n{\n public:\n int n, k;\n vector<int> a;\n int dp[(1 << 14) + 5][16];\n int find(int mask, int left)\n {\n \t// mask = to s | __kaizen__ | NORMAL | 2021-08-29T09:03:14.020857+00:00 | 2021-08-29T09:03:14.020905+00:00 | 74 | false | ```\nclass Solution\n{\n public:\n int n, k;\n vector<int> a;\n int dp[(1 << 14) + 5][16];\n int find(int mask, int left)\n {\n \t// mask = to store the state of already selected items\n \t// left = how much sessionTime is still left to consume\n if (mask == (1 << n) - 1)\n retur... | 1 | 0 | [] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | C++ | sub-mask enumeration | O(3^n) | c-sub-mask-enumeration-o3n-by-hit7sh-93qz | We can reach a mask from all of its submasks.\n```\nclass Solution {\npublic:\n int minSessions(vector& tasks, int sessionTime) {\n int n = tasks.size | hit7sh | NORMAL | 2021-08-29T07:22:06.092450+00:00 | 2021-08-29T08:24:09.747232+00:00 | 102 | false | We can reach a mask from all of its submasks.\n```\nclass Solution {\npublic:\n int minSessions(vector<int>& tasks, int sessionTime) {\n int n = tasks.size();\n vector<int> dp(1 << n, 100000);\n for (int mask = 0; mask < 1 << n; mask++) {\n int req = 0;\n for (int i = 0; i ... | 1 | 0 | [] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | [C++] Binary Search + DFS + Memo | c-binary-search-dfs-memo-by-dingdang2014-d0rg | If x is the minimum number of work sessions to finish the tasks, then any value of work sessions larger than x would also be enough to finish the tasks. Thus, | dingdang2014 | NORMAL | 2021-08-29T06:25:47.000372+00:00 | 2021-08-29T06:25:47.000402+00:00 | 161 | false | If x is the minimum number of work sessions to finish the tasks, then any value of work sessions larger than x would also be enough to finish the tasks. Thus, we can apply binary search to this question.\n\nThe initial `left` can be 0, and `right` is the size of the tasks (why?).\n\nThe first guess could be `mid = lef... | 1 | 0 | [] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | C++ Solution | DP + Bit masking | c-solution-dp-bit-masking-by-hackaton172-swtv | We denote which tasks have been done and which are yet to be done by the binary representation of a variable mask (basic masking). Now everytime we have to sele | hackaton1729 | NORMAL | 2021-08-29T05:49:51.137733+00:00 | 2021-08-29T18:06:23.375269+00:00 | 229 | false | We denote which tasks have been done and which are yet to be done by the binary representation of a variable mask (basic masking). Now everytime we have to select a task to do, we have the following choices : \n1. If the current task requires time <= the time remaining in your current session, you can either select thi... | 1 | 0 | ['Bit Manipulation', 'Recursion', 'Memoization'] | 1 |
minimum-number-of-work-sessions-to-finish-the-tasks | javascript bitmask dp 144ms | javascript-bitmask-dp-144ms-by-henrychen-jp1u | \nconst minSessions = (tasks, sessionTime) => {\n let n = tasks.length;\n let dp = Array(1 << n).fill(Number.MAX_SAFE_INTEGER);\n let valid = Array(1 < | henrychen222 | NORMAL | 2021-08-29T05:45:31.088337+00:00 | 2021-08-29T05:45:31.088399+00:00 | 336 | false | ```\nconst minSessions = (tasks, sessionTime) => {\n let n = tasks.length;\n let dp = Array(1 << n).fill(Number.MAX_SAFE_INTEGER);\n let valid = Array(1 << n).fill(false);\n for (let i = 0; i < 1 << n; i++) {\n let sum = 0;\n for (let j = 0; j < n; j++) {\n if (1 & (i >> j)) sum += ... | 1 | 0 | ['Dynamic Programming', 'Bitmask', 'JavaScript'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | C# - O(N * 2 ^ N + 3 ^ N) Dynamic Programming + Bit Masking | c-on-2-n-3-n-dynamic-programming-bit-mas-wqm7 | csharp\npublic int MinSessions(int[] tasks, int sessionTime)\n{\n\tint mask = 1 << tasks.Length;\n\tint[] sum = new int[mask];\n\tint[] d = new int[mask];\n\tAr | christris | NORMAL | 2021-08-29T05:07:07.942116+00:00 | 2021-08-29T05:17:19.542525+00:00 | 179 | false | ```csharp\npublic int MinSessions(int[] tasks, int sessionTime)\n{\n\tint mask = 1 << tasks.Length;\n\tint[] sum = new int[mask];\n\tint[] d = new int[mask];\n\tArray.Fill(d, 1000);\n\td[0] = 0;\n\n\tfor (int i = 1; i < mask; i++)\n\t{ \n\t\tfor (int j = 0; j < tasks.Length; j++)\n\t\t{\n\t\t\tif ((i & (1 <<... | 1 | 0 | [] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | [Java] Bitmask DP, O(N2^N) | java-bitmask-dp-on2n-by-blackpinklisa-hqlq | Let us let a bitmask represent the available tasks and the unavaliable tasks where a 1 bit represents that a task is still available and 0 bit represents a task | blackpinklisa | NORMAL | 2021-08-29T04:51:34.782355+00:00 | 2021-08-29T15:56:13.364921+00:00 | 154 | false | Let us let a bitmask represent the available tasks and the unavaliable tasks where a `1` bit represents that a task is still available and `0` bit represents a task that is unavailable. \n\nThen, we can let `dp[bitmask]` represent the minimum sessions required to fullfill all the tasks of that bitmask. \n\nTo solve for... | 1 | 0 | [] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | Simple backtracking avoiding repeated recursive calls using hash set - C++ | simple-backtracking-avoiding-repeated-re-8heg | Just note that only backtracking will lead to TLE as there will be many repeated calls - you just need to skip those.\nHope this helps!\n\n void fun(vectorta | rajanyadg | NORMAL | 2021-08-29T04:36:32.466778+00:00 | 2021-08-29T04:36:32.466819+00:00 | 123 | false | Just note that only backtracking will lead to TLE as there will be many repeated calls - you just need to skip those.\nHope this helps!\n\n void fun(vector<int>tasks,int s,int k,int session,set<pair<vector<int>,int>>&st,vector<int>&v){\n if(tasks.empty()){\n v.push_back(k+1);\n retur... | 1 | 0 | [] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | Bottom up bitmask DP | bottom-up-bitmask-dp-by-changheng-uz6x | Let dp[state][sessionTimeLeft] equals to the number of session we need, example: dp[1101][10] (binary 1101) means the number of sessions we need when selecting | changheng | NORMAL | 2021-08-29T04:35:40.374027+00:00 | 2021-08-29T04:38:54.176247+00:00 | 163 | false | Let `dp[state][sessionTimeLeft]` equals to the number of session we need, example: `dp[1101][10]` (binary `1101`) means the number of sessions we need when selecting first, second and the third item, and there are 10 seconds left.\n\nNow, if `time >= tasks[i]`, `dp[state][time - tasks[i]] = dp[prevState][time]`.\nOther... | 1 | 0 | ['Dynamic Programming', 'C'] | 0 |
minimum-number-of-work-sessions-to-finish-the-tasks | Python3, Greedy + DP | python3-greedy-dp-by-wu1meng2-9jae | Finish large tasks first ==> Sort tasks reversely\n2. Use DP to put as many tasks as possible into one session\n3. Log the DP path such that those tasks done in | wu1meng2 | NORMAL | 2021-08-29T04:24:18.732852+00:00 | 2021-08-29T04:40:00.910610+00:00 | 586 | false | 1. Finish large tasks first ==> Sort tasks reversely\n2. Use DP to put as many tasks as possible into one session\n3. Log the DP path such that those tasks done in the current session can be removed before starting the next session\n\n```\nclass Solution:\n def minSessions(self, tasks: List[int], sessionTime: int) -... | 1 | 0 | ['Python3'] | 1 |
minimum-number-of-work-sessions-to-finish-the-tasks | JAVA | Beat 100 % | Two Sum Idea | No bit-mask | No recursion | | java-beat-100-two-sum-idea-no-bit-mask-n-9sv9 | ```\n public int minSessions(int[] tasks, int sessionTime) {\n\t\t//reverse order sort\n tasks = Arrays.stream(tasks).boxed()\n .sorted(Col | uchihasasuke | NORMAL | 2021-08-29T04:22:31.839802+00:00 | 2021-08-29T04:25:04.737698+00:00 | 283 | false | ```\n public int minSessions(int[] tasks, int sessionTime) {\n\t\t//reverse order sort\n tasks = Arrays.stream(tasks).boxed()\n .sorted(Collections.reverseOrder())\n .mapToInt(Integer::intValue)\n .toArray();\n \n //Key is tasks[i], Value is counter\n Map<... | 1 | 3 | [] | 5 |
build-a-matrix-with-conditions | ✅💯🔥Explanations No One Will Give You🎓🧠VERY Detailed Approach🎯🔥Extremely Simple And Effective🔥 | explanations-no-one-will-give-youvery-de-6zdk | \n\n \n \n I am lucky that whatever fear I have inside me, my desire to win is always stronger.\n \n | heir-of-god | NORMAL | 2024-07-21T06:50:20.500352+00:00 | 2024-07-21T11:01:17.763787+00:00 | 19,845 | false | \n<blockquote>\n <p>\n <b>\n I am lucky that whatever fear I have inside me, my desire to win is always stronger.\n </b> \n </p>\n <p>\n --- Serena Williams ---\n </p>\n</blockquote>\n\n# \uD83D\uDC51Problem Explanation and Understanding... | 147 | 10 | ['Array', 'Hash Table', 'Graph', 'Topological Sort', 'Matrix', 'Python', 'C++', 'Java', 'Python3', 'JavaScript'] | 12 |
build-a-matrix-with-conditions | ✅Beats 100% -Explained with [ Video ] -C++/Java/Python/JS - Topological Sort - Explained in Detail | beats-100-explained-with-video-cjavapyth-qe4y | \n\n# YouTube Video Explanation:\n\n ### To watch the video please click on "Watch On Youtube" option available the left bottom corner of the thumbnail. \n\nIf | lancertech6 | NORMAL | 2024-07-21T01:13:02.889730+00:00 | 2024-07-21T01:43:49.144548+00:00 | 10,943 | false | \n\n# YouTube Video Explanation:\n\n<!-- ### To watch the video please click on "Watch On Youtube" option available the left bottom corner of the thumbnail. -->\n\n**If you want a vi... | 107 | 4 | ['Array', 'Graph', 'Topological Sort', 'Matrix', 'Python', 'C++', 'Java', 'JavaScript'] | 7 |
build-a-matrix-with-conditions | [C++ with explanation] Simple Topological Sort Implementation | c-with-explanation-simple-topological-so-c1pp | Overview\nThis problem was a standard Topological Sort problem. THANKYOU Leetcode for covering such concept after a long time! \n\nHow I figured it out as Topol | Code-O-Maniac | NORMAL | 2022-08-28T04:00:49.330021+00:00 | 2022-08-28T04:13:20.622777+00:00 | 8,350 | false | **Overview**\nThis problem was a standard **Topological Sort** problem. THANKYOU Leetcode for covering such concept after a long time! \n\n**How I figured it out as Topological Sort?**\n* Ordering of numbers were required column wise and row wise.\n* Ordering were given in pairs `a -> b`, which means `a` should come be... | 85 | 0 | ['Graph', 'Topological Sort', 'C'] | 17 |
build-a-matrix-with-conditions | Kahn's topo sort/DFS rows & cols build matrix||66ms Beats 99.72% | kahns-topo-sortdfs-rows-cols-build-matri-djik | Intuition\n Describe your first thoughts on how to solve this problem. \nUse Kahn\'s algorthm, topological sort.\nApply for rowConditions, rowConditions to find | anwendeng | NORMAL | 2024-07-21T01:33:13.435225+00:00 | 2024-07-22T10:48:47.346364+00:00 | 7,874 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse Kahn\'s algorthm, topological sort.\nApply for rowConditions, rowConditions to find the ordering in row & in col.\nThen find pos (i, j) for x where 1<=x<=k\n\n2nd approach uses DFS+degree as visited instead of Kahn\'s algorithm. Moreo... | 64 | 0 | ['Array', 'Depth-First Search', 'Breadth-First Search', 'Graph', 'Topological Sort', 'Matrix', 'C++'] | 10 |
build-a-matrix-with-conditions | Kahn's Algo | Topological Sort | BFS | C++ | Short and Easy to Understand Code | kahns-algo-topological-sort-bfs-c-short-ldaxm | \nvector<int> khansAlgo(vector<vector<int>> &r, int k){\n vector<int> cnt(k+1, 0);\n vector<int> adj[k+1];\n for(auto x:r){\n cn | surajpatel | NORMAL | 2022-08-28T04:02:58.273097+00:00 | 2022-08-28T09:47:55.770139+00:00 | 4,023 | false | ```\nvector<int> khansAlgo(vector<vector<int>> &r, int k){\n vector<int> cnt(k+1, 0);\n vector<int> adj[k+1];\n for(auto x:r){\n cnt[x[1]]++;\n adj[x[0]].push_back(x[1]);\n }\n vector<int> row;\n queue<int> q;\n for(int i=1;i<=k;i++){\n i... | 58 | 0 | ['Breadth-First Search', 'Topological Sort', 'C'] | 19 |
build-a-matrix-with-conditions | [Python 3] Explanation with pictures, Topological Sort | python-3-explanation-with-pictures-topol-2r40 | Detect if a circle exists in DAG\n\nHere is the BFS solution: start with dequeue of nodes with 0 indegree, update the indegree and add those nodes with 0 indegr | Bakerston | NORMAL | 2022-08-28T04:05:26.239710+00:00 | 2022-08-29T02:32:01.359657+00:00 | 2,563 | false | > Detect if a circle exists in DAG\n\nHere is the BFS solution: start with dequeue of nodes with 0 indegree, update the indegree and add those nodes with 0 indegree to dequeue. Once we are done, the sequence by which we pop the nodes are **one** workable order. \n\n\n* Add that vertex to the array representing topological s... | 41 | 0 | ['Topological Sort', 'C', 'Python', 'Java'] | 6 |
build-a-matrix-with-conditions | Topological Sort | topological-sort-by-votrubac-jw46 | We apply topological sort independently for both conditions. \n\nAs a refresher, we build a directed graph with k nodes, and each condition is a directed link b | votrubac | NORMAL | 2022-08-28T04:01:24.978818+00:00 | 2022-08-28T04:14:28.828284+00:00 | 3,337 | false | We apply topological sort independently for both conditions. \n\nAs a refresher, we build a directed graph with `k` nodes, and each condition is a directed link between the corresponding nodes.\n\n> We represent the graph with the adjacency list (`al`). Note that we use a set to hold linked nodes as we may have duplica... | 31 | 1 | [] | 10 |
build-a-matrix-with-conditions | [Python3] topological sort | python3-topological-sort-by-ye15-gwpv | Please pull this commit for solutions of weekly 308. \n\nIntuition\nThe workhorse of this problem is topological sort. The orders in aboveConditions and leftCon | ye15 | NORMAL | 2022-08-28T04:02:16.692070+00:00 | 2022-08-28T04:49:28.748106+00:00 | 1,291 | false | Please pull this [commit](https://github.com/gaosanyong/leetcode/commit/ea6bc01b091cbf032b9c7ac2d3c09cb4f5cd0d2d) for solutions of weekly 308. \n\n**Intuition**\nThe workhorse of this problem is topological sort. The orders in `aboveConditions` and `leftConditions` construct two graphs. Via topological sort, the order ... | 24 | 0 | ['Python3'] | 8 |
build-a-matrix-with-conditions | C++ | Topological Sort | c-topological-sort-by-_naaz-pp81 | Perform topological sort on rowConditions & colConditions\n The index of element in topological sort of rowConditions will be the rowIndex. Similarly, for the i | _naaz | NORMAL | 2022-08-28T04:01:56.772272+00:00 | 2022-08-28T11:53:26.270422+00:00 | 1,697 | false | * Perform **topological sort** on rowConditions & colConditions\n* The index of element in topological sort of rowConditions will be the rowIndex. Similarly, for the index of element in topological sort of colConditions will the colIndex of the element in the result grid\n* Time complexity of Topological sort is ```O(V... | 21 | 1 | ['Topological Sort', 'C'] | 7 |
build-a-matrix-with-conditions | No one can give such quality code... Bests 98.9% users.... #Quality code | no-one-can-give-such-quality-code-bests-lw8dn | \n\n# Python\n\nclass Solution:\n\n def buildMatrix(\n\n self,\n\n k: int,\n\n rowConditions: List[List[int]],\n\n colConditions: | Aim_High_212 | NORMAL | 2024-07-21T01:19:50.045407+00:00 | 2024-07-21T04:10:52.005083+00:00 | 2,100 | false | \n\n# Python\n```\nclass Solution:\n\n def buildMatrix(\n\n self,\n\n k: int,\n\n rowConditions: List[List[int]],\n\n colConditions: List[List[int]],\n\n ) -> List[List[int]]:\n\n # Store the topologically sorted sequences.\n\n order_rows = self.__topoSort(rowConditions, ... | 19 | 3 | ['Array', 'Graph', 'Topological Sort', 'C', 'Matrix', 'Python', 'Java', 'Python3', 'JavaScript'] | 7 |
build-a-matrix-with-conditions | 💯✅🔥Detailed Easy Java ,Python3 ,C++ Solution|| 10 ms ||≧◠‿◠≦✌ | detailed-easy-java-python3-c-solution-10-1t51 | Intuition\nThe problem requires constructing a k x k matrix where each element must satisfy certain ordering constraints specified by rowConditions and colCondi | suyalneeraj09 | NORMAL | 2024-07-21T03:41:08.992190+00:00 | 2024-07-21T03:41:08.992219+00:00 | 2,522 | false | # Intuition\nThe problem requires constructing a `k x k` matrix where each element must satisfy certain ordering constraints specified by `rowConditions` and `colConditions`. The constraints dictate that if there is a condition like `[a, b]`, then `a` must appear before `b` in the respective row or column.\n\nTo solve ... | 17 | 3 | ['Array', 'Graph', 'Topological Sort', 'Matrix', 'C++', 'Java', 'Python3'] | 3 |
build-a-matrix-with-conditions | Topological Sort & cycle detection using DFS | JAVA | 18ms | 100% | topological-sort-cycle-detection-using-d-384g | \nclass Solution {\n public int[][] buildMatrix(int k, int[][] rowConditions, int[][] colConditions) {\n \n int[][] ans = new int[k][k];\n | akrchaubey | NORMAL | 2022-08-28T04:04:51.692761+00:00 | 2022-08-28T06:57:00.329541+00:00 | 923 | false | ```\nclass Solution {\n public int[][] buildMatrix(int k, int[][] rowConditions, int[][] colConditions) {\n \n int[][] ans = new int[k][k];\n \n // create adjacency List for the rows and columns\n Map<Integer, Set<Integer>> adjListRow = new HashMap<>();\n Map<Integer, Set<In... | 10 | 1 | ['Depth-First Search', 'Topological Sort', 'Java'] | 2 |
build-a-matrix-with-conditions | Simple and Easy C++ | Kahn's Algorithm | Topological Sort | BFS | OOPS | simple-and-easy-c-kahns-algorithm-topolo-ph9y | Algorithm\n1. Create graph for both rowConditions and colConditions.\n2. Check if both graphs are acyclic using Kahn\'s Algorithm. If either graph is cyclic, th | neeleshgupta93 | NORMAL | 2022-08-30T18:34:08.327618+00:00 | 2022-08-30T18:34:08.327658+00:00 | 489 | false | **Algorithm**\n1. Create graph for both ```rowConditions``` and ```colConditions```.\n2. Check if both graphs are acyclic using Kahn\'s Algorithm. If either graph is cyclic, then return ```[]```.\n3. Kahn\'s Algorithm will give ```topological sorting (topo1 and topo2) ``` for both graphs.\n4. ```topo1``` will give posi... | 9 | 0 | ['Breadth-First Search', 'Graph', 'Topological Sort', 'C'] | 2 |
build-a-matrix-with-conditions | [LeetCode The Hard Way] Kahn's Algorithm with Explanation | leetcode-the-hard-way-kahns-algorithm-wi-0cv3 | Please check out LeetCode The Hard Way for more solution explanations and tutorials. If you like it, please give a star and watch my Github Repository.\n\n---\n | __wkw__ | NORMAL | 2022-08-29T12:10:47.741956+00:00 | 2022-08-29T12:11:00.952853+00:00 | 612 | false | Please check out [LeetCode The Hard Way](https://wingkwong.github.io/leetcode-the-hard-way/) for more solution explanations and tutorials. If you like it, please give a star and watch my [Github Repository](https://github.com/wingkwong/leetcode-the-hard-way).\n\n---\n\n```cpp\nclass Solution {\npublic:\n // there is... | 7 | 0 | ['Breadth-First Search', 'Topological Sort', 'C', 'C++'] | 2 |
build-a-matrix-with-conditions | Python | Topological Sorting | python-topological-sorting-by-khosiyat-br1b | see the Successfully Accepted Submission\n\n# Code\n\nclass Solution:\n def buildMatrix(self, k: int, rowConditions: List[List[int]], colConditions: List[Lis | Khosiyat | NORMAL | 2024-07-21T08:11:00.429213+00:00 | 2024-07-21T08:11:00.429240+00:00 | 511 | false | [see the Successfully Accepted Submission](https://leetcode.com/problems/build-a-matrix-with-conditions/submissions/1328224805/?envType=daily-question&envId=2024-07-21)\n\n# Code\n```\nclass Solution:\n def buildMatrix(self, k: int, rowConditions: List[List[int]], colConditions: List[List[int]]) -> List[List[int]]:\... | 6 | 0 | ['Python3'] | 0 |
build-a-matrix-with-conditions | easy c++ sol |Kahn's Algo | Topological Sort | BFS | C++ | Short and Easy to Understand Code | easy-c-sol-kahns-algo-topological-sort-b-vleh | 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 | sarthakgoel84 | NORMAL | 2024-07-21T05:45:26.316507+00:00 | 2024-07-21T05:45:26.316540+00:00 | 1,126 | 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)$$ --... | 6 | 0 | ['C++'] | 6 |
build-a-matrix-with-conditions | Simple and Clean C++ solution using kahn's algorithm | simple-and-clean-c-solution-using-kahns-t7rg0 | Intuition\nSimple idea behind the solution is if we take projections of non zero elements of matrix along the row and column , those projected rows and colums s | Vaibhav_Potdar | NORMAL | 2023-03-15T20:12:58.084690+00:00 | 2023-03-15T20:26:13.347544+00:00 | 435 | false | # Intuition\nSimple idea behind the solution is if we take projections of non zero elements of matrix along the row and column , those projected rows and colums should be topologically sorted. \nSo we will first find valid orders of row and columns. seperately and then we will form the matrix. \n\n\n```\nclass Solution... | 6 | 0 | ['Breadth-First Search', 'Graph', 'Topological Sort', 'C++'] | 4 |
build-a-matrix-with-conditions | Easy Explanation + Code with comments | Doubt of building matrix at end | Java | BFS | TopSort | easy-explanation-code-with-comments-doub-1o13 | From diffferent you might already know it is topological sort. But there is no harm in revising it.\nApproach:\nIn question, condition is given that a number sh | anuj0503 | NORMAL | 2022-09-02T16:50:13.760937+00:00 | 2022-09-02T16:50:13.760976+00:00 | 268 | false | From diffferent you might already know it is topological sort. But there is no harm in revising it.\nApproach:\nIn question, condition is given that a number should occur before other number in row/column and such conditions are many. This is cue for topological sort.\n\nNow, imagine we dont have to create 2D matrix at... | 6 | 0 | ['Breadth-First Search', 'Topological Sort', 'Java'] | 2 |
build-a-matrix-with-conditions | Graph solution and runtime beats 97.22% [EXPLAINED] | graph-solution-and-runtime-beats-9722-ex-qogb | IntuitionWe are given conditions that specify the relative positions of numbers in a matrix, both row-wise and column-wise. The goal is to arrange numbers such | r9n | NORMAL | 2024-12-23T22:20:08.949808+00:00 | 2024-12-23T22:20:08.949808+00:00 | 17 | false | # Intuition
We are given conditions that specify the relative positions of numbers in a matrix, both row-wise and column-wise. The goal is to arrange numbers such that these conditions are satisfied while filling a k x k matrix.
# Approach
Treat the row and column conditions as directed graphs and perform topological ... | 5 | 0 | ['Array', 'Graph', 'Topological Sort', 'Matrix', 'Python3'] | 0 |
build-a-matrix-with-conditions | BFS - Intuition & Approach Explained C++ | bfs-intuition-approach-explained-c-by-re-iz2w | Intuition\n Describe your first thoughts on how to solve this problem. \nWhen I first read the problem, I noticed that there was a dependency involved. Whenever | reetisharma | NORMAL | 2024-07-21T12:22:40.677269+00:00 | 2024-07-21T12:25:20.137532+00:00 | 272 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWhen I first read the problem, I noticed that there was a dependency involved. Whenever we encounter dependency, we should think of graphs. Moreover, there was an additional constraint of ordering, which implies that we need to sort the e... | 5 | 0 | ['Breadth-First Search', 'Graph', 'C++'] | 1 |
build-a-matrix-with-conditions | Easy Solution | Topological Sort | Python | C++ | easy-solution-topological-sort-python-c-gso83 | Approach\n1. Initialize and Populate the Graphs for rows and Columns:\n2. then create a topological sort function that sorts the given action in such a order th | Sachinonly__ | NORMAL | 2024-07-21T10:10:10.618486+00:00 | 2024-07-21T19:56:46.205797+00:00 | 267 | false | # Approach\n1. Initialize and Populate the Graphs for rows and Columns:\n2. then create a topological sort function that sorts the given action in such a order that if theres a dependency of child over a parent then child will always come after the parent. \n - Create a stack deque(why deque becuse it will help us a... | 5 | 0 | ['Array', 'Graph', 'Topological Sort', 'Matrix', 'Python', 'C++', 'Python3'] | 0 |
build-a-matrix-with-conditions | JAVA Solution Explained in HINDI | java-solution-explained-in-hindi-by-the_-pa92 | https://youtu.be/HmnmBjjyZeo\n\nFor explanation, please watch the above video and do like, share and subscribe the channel. \u2764\uFE0F Also, please do upvote | The_elite | NORMAL | 2024-07-21T08:39:24.767501+00:00 | 2024-07-21T08:39:24.767525+00:00 | 439 | false | https://youtu.be/HmnmBjjyZeo\n\nFor explanation, please watch the above video and do like, share and subscribe the channel. \u2764\uFE0F Also, please do upvote the solution if you liked it.\n\n# Subscribe:- [ReelCoding](https://www.youtube.com/@reelcoding?sub_confirmation=1)\n\n## Subscribe Goal:- 500\n## Current Subsc... | 5 | 0 | ['Java'] | 0 |
build-a-matrix-with-conditions | ✅Beats 100% || Made it easy for you || C++/Java/Python/JS || Topological Sort || Explained in Detail | beats-100-made-it-easy-for-you-cjavapyth-2soc | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem is about arranging integers from 1 to \uD835\uDC58\nk in a \uD835\uDC58 \xD | _Rachi | NORMAL | 2024-07-21T05:33:02.940219+00:00 | 2024-07-21T05:33:02.940244+00:00 | 503 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem is about arranging integers from 1 to \uD835\uDC58\nk in a \uD835\uDC58 \xD7 \uD835\uDC58 matrix such that: \n1. Specific integers appear in certain rows (based on rowConditions).\n2. Specific integers appear in certain column... | 5 | 0 | ['Array', 'Graph', 'Topological Sort', 'Matrix', 'Python', 'C++', 'Java', 'JavaScript'] | 5 |
build-a-matrix-with-conditions | 🔥🔥 ✅ Beats 100 %solutions with Detailed explanation || C++ || JAVA || Python | beats-100-solutions-with-detailed-explan-yr23 | Intuition Behind the Solution\n\nThe problem involves building a \( k \times k \) matrix with specific conditions on the ordering of rows and columns. The core | originalpandacoder | NORMAL | 2024-07-21T05:09:25.536822+00:00 | 2024-07-21T05:09:25.536849+00:00 | 511 | false | # Intuition Behind the Solution\n\nThe problem involves building a \\( k \\times k \\) matrix with specific conditions on the ordering of rows and columns. The core idea is to use topological sorting to determine a valid order of elements based on the given conditions.\n\nHere\u2019s a step-by-step breakdown of the int... | 5 | 0 | ['Array', 'Graph', 'Topological Sort', 'Matrix', 'C++', 'Java'] | 2 |
build-a-matrix-with-conditions | Rust - Kahn's Algorithm with Matrix Manipulation | rust-kahns-algorithm-with-matrix-manipul-p2v1 | Solution - github\n\nProblem List\n#KahnsAlgorithm - github\n#MatrixManipulation - github\n\n#DirectedGraph - github\n#DetectCycle-Graph - github\n#Graph - gith | idiotleon | NORMAL | 2022-08-28T04:20:02.740471+00:00 | 2022-08-28T05:19:25.733728+00:00 | 321 | false | Solution - [github](https://github.com/An7One/lc_soln_rust_leon/tree/main/src/leetcode/lvl4/lc2392)\n\n<b>Problem List</b>\n#KahnsAlgorithm - [github](https://github.com/An7One/leetcode-problems-by-tag-an7one/blob/main/txt/by_algorithm/search/breath_first_search/by_algorithm/kahns_algorithm.txt)\n#MatrixManipulation - ... | 5 | 0 | ['Topological Sort', 'Rust'] | 2 |
build-a-matrix-with-conditions | [Python] Topological Sort Explained | python-topological-sort-explained-by-zsk-qa6b | rows and cols are independent, just run 2 topological sorts on each direction. time complexity is O(k^2)\n\n\nclass Solution:\n def buildMatrix(self, k: int, | zsk99881 | NORMAL | 2022-08-28T04:01:28.217401+00:00 | 2022-08-28T04:42:06.682923+00:00 | 352 | false | rows and cols are independent, just run 2 topological sorts on each direction. time complexity is O(k^2)\n\n```\nclass Solution:\n def buildMatrix(self, k: int, rowConditions: List[List[int]], colConditions: List[List[int]]) -> List[List[int]]:\n res = [[0 for _ in range(k)] for _ in range(k)]\n \n ... | 5 | 1 | [] | 1 |
build-a-matrix-with-conditions | Topological Sort | BFS | DFS | Short and Easy to Understand C++ Code | topological-sort-bfs-dfs-short-and-easy-x81p1 | It can be easily observed that the problem can be solved independently for rows and columns. First we can find the row number for each number from 1 to K and th | shekabhi1208 | NORMAL | 2022-08-28T04:00:53.942540+00:00 | 2022-08-29T16:58:02.202964+00:00 | 539 | false | It can be easily observed that the problem can be solved independently for rows and columns. First we can find the row number for each number from 1 to K and then find the column number for each of them. \nHere, If we see the problem as a graph problem where we have nodes from 1 to K and edges as the dependencies given... | 5 | 1 | ['Depth-First Search', 'Breadth-First Search', 'Graph', 'Topological Sort', 'C'] | 1 |
build-a-matrix-with-conditions | Easy Intuition||TOPO SORT|| | easy-intuitiontopo-sort-by-ankii09102003-t0sj | Intuition\nsince we have given the boundations like this should appear first than this like these.... so we can directly think of topological sort and then afte | ankii09102003 | NORMAL | 2024-08-23T16:18:44.500856+00:00 | 2024-08-23T16:18:44.500889+00:00 | 57 | false | # Intuition\nsince we have given the boundations like this should appear first than this like these.... so we can directly think of topological sort and then after getting order for row and column we can just use map to decide the actual row and column \n\n# Approach\n<!-- Describe your approach to solving the problem... | 4 | 0 | ['C++'] | 0 |
build-a-matrix-with-conditions | Easy to Understand | easy-to-understand-by-twasim-b2jx | Intuition\n Describe your first thoughts on how to solve this problem. \nTopological Ordering.\n# Approach\n Describe your approach to solving the problem. \nTh | twasim | NORMAL | 2024-07-21T19:53:01.301607+00:00 | 2024-07-21T19:53:01.301650+00:00 | 66 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTopological Ordering.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe problem is composition of two medium problem\n1.detecting cycle for edges case\n2.Degree vector is used to assign the topological ordering to ... | 4 | 0 | ['Graph', 'Topological Sort', 'C++'] | 0 |
build-a-matrix-with-conditions | Beginner Friendly Solution with Graph and Topological Sort + Visualization (Step By Step) 😊😊 | beginner-friendly-solution-with-graph-an-m5pu | Intuition\nThe code aims to construct a matrix of size k x k based on two sets of conditions: rowConditions and colConditions. These conditions specify relation | briancode99 | NORMAL | 2024-07-21T07:33:57.320547+00:00 | 2024-07-21T07:33:57.320565+00:00 | 80 | false | # Intuition\nThe code aims to construct a matrix of size k x k based on two sets of conditions: rowConditions and colConditions. These conditions specify relationships between elements within rows and columns. The problem seems to involve finding a valid ordering of elements that satisfies these relationships, possibly... | 4 | 0 | ['Graph', 'Topological Sort', 'JavaScript'] | 0 |
build-a-matrix-with-conditions | Java Clean Solution | Daily Challenge | java-clean-solution-daily-challenge-by-s-x2wr | Code\n\nclass Solution {\n\n private List<Integer> helperSort(int[][] arr, int k) {\n int[] deg = new int[k];\n List<List<Integer>> list = new | Shree_Govind_Jee | NORMAL | 2024-07-21T03:54:30.603155+00:00 | 2024-07-21T03:54:30.603185+00:00 | 317 | false | # Code\n```\nclass Solution {\n\n private List<Integer> helperSort(int[][] arr, int k) {\n int[] deg = new int[k];\n List<List<Integer>> list = new ArrayList<>();\n for (int i = 0; i < k; i++) {\n list.add(new ArrayList<>());\n }\n\n Queue<Integer> q = new LinkedList<>()... | 4 | 0 | ['Array', 'Graph', 'Topological Sort', 'Matrix', 'Java'] | 2 |
build-a-matrix-with-conditions | [Python3] Topological Sort - Simple Solution | python3-topological-sort-simple-solution-zr3t | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nFind the order for row and col respectively and then assign them to the m | dolong2110 | NORMAL | 2023-09-07T18:39:37.684805+00:00 | 2023-09-07T18:39:37.684830+00:00 | 190 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nFind the order for row and col respectively and then assign them to the matrix. Note that there are only `k` number need to assign which is also the side of square matrix. Thus we can assign each number in each unique row an... | 4 | 0 | ['Greedy', 'Graph', 'Topological Sort', 'Matrix', 'Python3'] | 3 |
build-a-matrix-with-conditions | Heavely Commented || TopoSort || Khan's Algorithm || BFS || 100% Simple✅✅✅ | heavely-commented-toposort-khans-algorit-faul | \nclass Solution {\npublic:\n \n\t// Function to create adjacency List and indegree of the graph\n void adjListCreator(vector<vector<int>>&conditions,vect | C___vam2107 | NORMAL | 2023-07-12T09:42:15.124515+00:00 | 2023-07-12T09:42:15.124544+00:00 | 68 | false | ```\nclass Solution {\npublic:\n \n\t// Function to create adjacency List and indegree of the graph\n void adjListCreator(vector<vector<int>>&conditions,vector<vector<int>>&adj,vector<int>& indegree){\n for(auto &it:conditions){\n int u=it[0];\n int v=it[1];\n adj[v].push_b... | 4 | 0 | ['Breadth-First Search', 'Graph', 'Topological Sort'] | 3 |
build-a-matrix-with-conditions | Topological Sort with Explanation and Complexity Analysis | topological-sort-with-explanation-and-co-2ef8 | Rationale\n The row and column dependencies could be established with a directed graph, where any edge from vertex A to vertex B denotes that vertex A should co | wickedmishra | NORMAL | 2022-08-28T04:01:55.609889+00:00 | 2022-08-28T04:08:16.420257+00:00 | 170 | false | ##### Rationale\n* The row and column dependencies could be established with a directed graph, where any edge from vertex A to vertex B denotes that vertex A should come before vertex B in the matrix\n* To resolve the dependencies, we could sort them topologically\n* If the relationship is acyclic, we would have all th... | 4 | 1 | ['Breadth-First Search', 'Topological Sort'] | 0 |
build-a-matrix-with-conditions | Java | Topological Sort | No Cycle -> No Conflict | java-topological-sort-no-cycle-no-confli-gdag | Model\nWe can model this as a directed graph, with above -> below and left -> right.\nWe will need to verify that there is no cycle and find out where its suppo | Student2091 | NORMAL | 2022-08-28T04:01:46.475812+00:00 | 2022-08-28T05:33:48.513511+00:00 | 535 | false | #### Model\nWe can model this as a directed graph, with `above -> below` and `left -> right`.\nWe will need to verify that there is no cycle and find out where its supposed `row` and `col` position is.\n\n#### Strategy\nOne crucial observation is that the grid size is `k x k` and we have `k` element to fill. \nAny row ... | 4 | 0 | ['Topological Sort', 'Java'] | 4 |
build-a-matrix-with-conditions | Find Topo sort and compare | Easy to understand | find-topo-sort-and-compare-easy-to-under-mg8j | \nclass Solution {\n public int[][] buildMatrix(int k, int[][] rowConditions, int[][] colConditions) {\n int rowTopo[] = topoSort(k,rowConditions);\n | anilkumawat3104 | NORMAL | 2024-07-21T10:50:02.735714+00:00 | 2024-07-21T10:50:02.735755+00:00 | 27 | false | ```\nclass Solution {\n public int[][] buildMatrix(int k, int[][] rowConditions, int[][] colConditions) {\n int rowTopo[] = topoSort(k,rowConditions);\n int colTopo[] = topoSort(k,colConditions);\n int ans[][] = new int[k][k];\n if(rowTopo.length==0||colTopo.length==0)\n return... | 3 | 0 | ['Graph', 'Topological Sort', 'Matrix', 'Java'] | 0 |
build-a-matrix-with-conditions | A C Solution | a-c-solution-by-well_seasoned_vegetable-9tw4 | Code\n\n#define MAX_K 400\n\nstruct node {\n int val;\n struct node* next;\n};\n\nstruct graph {\n struct node* head[MAX_K + 1];\n int inDegree[MAX_ | well_seasoned_vegetable | NORMAL | 2024-07-21T08:08:18.373351+00:00 | 2024-07-21T13:22:04.234544+00:00 | 81 | false | # Code\n```\n#define MAX_K 400\n\nstruct node {\n int val;\n struct node* next;\n};\n\nstruct graph {\n struct node* head[MAX_K + 1];\n int inDegree[MAX_K + 1];\n};\n\nvoid addEdge(struct graph* graph, int from, int to) {\n struct node* new = malloc(sizeof(struct node));\n new->val = to;\n new->nex... | 3 | 0 | ['C'] | 0 |
build-a-matrix-with-conditions | C++ || independent topological sort | c-independent-topological-sort-by-heder-wrtq | Topological sort for rows and cols independently and then combine the outcome.\n\n\n static vector<vector<int>> buildMatrix(int k,\n\t vector<vector<i | heder | NORMAL | 2022-08-29T19:54:37.860212+00:00 | 2022-08-29T19:54:37.860243+00:00 | 162 | false | Topological sort for rows and cols independently and then combine the outcome.\n\n```\n static vector<vector<int>> buildMatrix(int k,\n\t vector<vector<int>>& rowConditions,\n\t\t vector<vector<int>>& colConditions) {\n // Topological sort for rows and cols independently.\n const vector<int> ... | 3 | 0 | ['Topological Sort', 'C'] | 0 |
build-a-matrix-with-conditions | C++ - Topological Sort | beats 100% in both Time and Space Complexity | c-topological-sort-beats-100-in-both-tim-2noh | By using topo sort we are generating the order of sequence of numbers in row,column and here we also check whether there are any cycles in row,col directed grap | Naveen_kotha | NORMAL | 2022-08-29T05:25:36.240929+00:00 | 2022-08-29T05:25:36.240976+00:00 | 122 | false | By using topo sort we are generating the order of sequence of numbers in row,column and here we also check **whether there are any cycles in row,col directed graph**.\nIf there is any cycle in row or col directed graph, then we return an empty array\nWe are using topo sort because there is a **relation** between number... | 3 | 1 | ['Topological Sort', 'C'] | 1 |
build-a-matrix-with-conditions | Topological sorting | Kahn's algorithm | topological-sorting-kahns-algorithm-by-n-ihl0 | We have hierarchy given to us by rowConditions and colConditions. We can map that hierarchy with a topological ordering algorithm.\n\nLet\'s find the order we c | nadaralp | NORMAL | 2022-08-28T09:04:25.123692+00:00 | 2022-08-28T09:08:45.398533+00:00 | 336 | false | We have hierarchy given to us by rowConditions and colConditions. We can map that hierarchy with a topological ordering algorithm.\n\nLet\'s find the order we can place rows and columns separately by running the Kahn\'s topsort algorithm. If there is a cycle detected we know we cannot have a valid order, we return `[]`... | 3 | 1 | ['Python'] | 1 |
build-a-matrix-with-conditions | Beats 99% | Easy Topological Sort | Cycle Detection | Simple Approach | beats-99-easy-topological-sort-cycle-det-zp01 | IntuitionThe problem requires constructing a 𝑘 × 𝑘 matrix such that two independent sets of conditions on rows and columns are satisfied. The key insight is tha | pranjaykapoor | NORMAL | 2025-01-24T10:50:56.794208+00:00 | 2025-01-24T10:50:56.794208+00:00 | 41 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem requires constructing a `𝑘 × 𝑘` matrix such that two independent sets of conditions on rows and columns are satisfied. The key insight is that the problem can be approached as two topological sorting tasks:
1. One for row con... | 2 | 0 | ['Array', 'Graph', 'Topological Sort', 'Matrix', 'C++'] | 0 |
build-a-matrix-with-conditions | Simple || Easy ||Basic Understanding Approach || step by step || optimized ||Kahn algorithm||O(N) | simple-easy-basic-understanding-approach-x56q | Simple || Easy || Basic Understanding Approach || step by step || optimized|| Kahn algorithm || O(N) \n\nBuild a Matrix With Conditions\n\n# Intuition\n1. Intui | VaidyaPS | NORMAL | 2024-07-29T09:15:11.810868+00:00 | 2024-07-29T09:15:11.810901+00:00 | 5 | false | Simple || Easy || Basic Understanding Approach || step by step || optimized|| Kahn algorithm || O(N) \n\nBuild a Matrix With Conditions\n\n# Intuition\n1. Intuition in very simple we need to make a matrix by given condition where we have 2d matrix consist of row (above, bottom) and col (left,right). \n2. we can assume ... | 2 | 0 | ['Array', 'Graph', 'Topological Sort', 'Matrix', 'C++'] | 1 |
build-a-matrix-with-conditions | Simply Explained ✨ | simply-explained-by-aayushbharti-ue0s | Intuition\nTo solve this problem, we need to find a valid way to place each number from 1 to k in a k x k matrix such that all given row and column conditions a | AayushBharti | NORMAL | 2024-07-21T17:28:04.650798+00:00 | 2024-07-21T17:28:04.650833+00:00 | 25 | false | # Intuition\nTo solve this problem, we need to find a valid way to place each number from 1 to k in a k x k matrix such that all given row and column conditions are satisfied. This can be done using topological sorting. We first create the topological order for rows and columns separately using the given conditions and... | 2 | 0 | ['Java'] | 0 |
build-a-matrix-with-conditions | ✅💯🔥Explanations No One Will Give You🎓🧠Very Detailed Approach🎯🔥Extremely Simple And Effective🔥 | explanations-no-one-will-give-youvery-de-uq8z | \n# Code\n\nclass Solution {\npublic:\n vector<int> toposort(vector<vector<int>>& edges, int n) {\n unordered_map<int, vector<int>> adj;\n vect | ShivanshGoel1611 | NORMAL | 2024-07-21T15:10:14.997150+00:00 | 2024-07-21T15:11:21.371606+00:00 | 86 | false | \n# Code\n```\nclass Solution {\npublic:\n vector<int> toposort(vector<vector<int>>& edges, int n) {\n unordered_map<int, vector<int>> adj;\n vector<int> indegree(n + 1, 0);\n for (vector<int>& edge : edges) {\n int u = edge[0];\n int v = edge[1];\n adj[u].push_b... | 2 | 1 | ['Graph', 'Topological Sort', 'C', 'Python', 'C++', 'Java', 'Python3', 'JavaScript'] | 1 |
build-a-matrix-with-conditions | Beats 100% || Easiest and Cleanest Logic || Topological Sort | beats-100-easiest-and-cleanest-logic-top-az3f | 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 | SPA111 | NORMAL | 2024-07-21T13:43:13.020670+00:00 | 2024-07-21T13:43:13.020701+00:00 | 26 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 2 | 0 | ['C++'] | 0 |
build-a-matrix-with-conditions | Easy Approach and Clear Structure ! Beats 100% in runtime ! #TopologicalSort | easy-approach-and-clear-structure-beats-a75jx | Intuition\n Describe your first thoughts on how to solve this problem. \nThink is problem as a "GRAPH" problem. The first and second number in x-conditions just | alonza_0314 | NORMAL | 2024-07-21T10:59:58.134931+00:00 | 2024-07-21T10:59:58.134960+00:00 | 103 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThink is problem as a "GRAPH" problem. The first and second number in x-conditions just like a from u to v edge. Then, use topological sort to solve this problem.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n**F... | 2 | 0 | ['Go'] | 1 |
build-a-matrix-with-conditions | Beats 100% || Made it easy for you || C++|| Topological Sort || Matrix Filling | beats-100-made-it-easy-for-you-c-topolog-hdh5 | \n### Problem Breakdown\n\n1. Topological Sorting: The problem can be translated into a graph problem where rowConditions and colConditions provide directed edg | itachiuchiha14 | NORMAL | 2024-07-21T08:11:58.770520+00:00 | 2024-07-21T08:11:58.770547+00:00 | 195 | false | \n### Problem Breakdown\n\n1. **Topological Sorting**: The problem can be translated into a graph problem where `rowConditions` and `colConditions` provide directed edges indicating the order of elements in rows and columns respectively.\n2. **Matrix Construction**: Once the topological orderings are obtained, we need ... | 2 | 0 | ['Array', 'Graph', 'Topological Sort', 'Matrix', 'C++'] | 0 |
build-a-matrix-with-conditions | C++ / Python Solution | Matrix | Graph | Topological Sorting | Kahn's Algorithm | | c-python-solution-matrix-graph-topologic-zpon | Intuition\nTopological Sorting.\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nUse Kahn\'s Algorithm.\n Describe your approach to | Kaushik_Prajapati | NORMAL | 2024-07-21T05:55:07.746145+00:00 | 2024-07-21T05:55:07.746166+00:00 | 105 | false | # Intuition\nTopological Sorting.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nUse Kahn\'s Algorithm.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(K^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexit... | 2 | 0 | ['Array', 'Graph', 'Topological Sort', 'Matrix', 'C++', 'Python3'] | 1 |
build-a-matrix-with-conditions | Kotlin Topological sort and build matrix | kotlin-topological-sort-and-build-matrix-f46a | Using topo sort Kann algorithm on row and column separately and then use that to rebuild matrix. Since only k number from 1..k in k * k matrix, each number can | james4388 | NORMAL | 2024-07-21T05:24:47.531243+00:00 | 2024-07-21T05:24:47.531289+00:00 | 29 | false | Using topo sort Kann algorithm on row and column separately and then use that to rebuild matrix. Since only k number from 1..k in k * k matrix, each number can be on one row and one column, no overlap\n```\nclass Solution {\n fun topologicalSort(edges: Array<IntArray>, n: Int): List<Int> {\n val graph = mutab... | 2 | 0 | ['Topological Sort', 'Kotlin'] | 0 |
build-a-matrix-with-conditions | C# Solution for Build a Matrix With Conditions Problem | c-solution-for-build-a-matrix-with-condi-a763 | Intuition\n Describe your first thoughts on how to solve this problem. \nThe approach involves:\n\n\t1.\tTopological Sorting: Using Kahn\u2019s algorithm to fin | Aman_Raj_Sinha | NORMAL | 2024-07-21T04:17:20.789269+00:00 | 2024-07-21T04:17:20.789305+00:00 | 170 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe approach involves:\n\n\t1.\tTopological Sorting: Using Kahn\u2019s algorithm to find the order of elements based on the given constraints.\n\t2.\tMatrix Construction: Filling in the matrix based on the sorted row and column orders.\n\... | 2 | 0 | ['C#'] | 2 |
build-a-matrix-with-conditions | Topological Sort (w/ Comments) | topological-sort-w-comments-by-alexplump-t6jy | Intuition\n Describe your first thoughts on how to solve this problem. \nDetermine what number has no numbers before it at any time.\n\n# Approach\n Describe yo | alexplump | NORMAL | 2024-07-21T02:46:21.050613+00:00 | 2024-07-21T02:46:21.050633+00:00 | 134 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nDetermine what number has no numbers before it at any time.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nCreate a dictionary of what numbers precede any number.\n\n# Complexity\n- Time complexity:\n<!-- Add your... | 2 | 0 | ['C#'] | 2 |
build-a-matrix-with-conditions | Construct a 2D Matrix with Conditions. | construct-a-2d-matrix-with-conditions-by-a2iu | Intuition\n Describe your first thoughts on how to solve this problem. \nTo solve this problem, we need to determine the relative positioning of numbers in a ma | pathik5 | NORMAL | 2024-07-21T02:12:46.798990+00:00 | 2024-07-21T02:12:46.799013+00:00 | 233 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo solve this problem, we need to determine the relative positioning of numbers in a matrix based on given row and column constraints. This is similar to a scheduling problem where tasks have dependencies. The dependencies in this case ar... | 2 | 1 | ['Matrix', 'C++'] | 3 |
build-a-matrix-with-conditions | Python Topo Sort | python-topo-sort-by-hong_zhao-q9qc | Intuition\n Describe your first thoughts on how to solve this problem. \nUse topological sort to find the order of row and col\n\nIn the first example:\n\n[3,0, | hong_zhao | NORMAL | 2024-07-21T01:27:03.187761+00:00 | 2024-07-21T02:08:01.095391+00:00 | 524 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse topological sort to find the order of row and col\n\nIn the first example:\n```\n[3,0,0]\n[0,0,1]\n[0,2,0]\n```\nThe row order from top to bottom is `3 -> 1 -> 2`\nThe col order from left to right is `3 -> 2 -> 1`\n\nNow we know the p... | 2 | 0 | ['Python3'] | 4 |
build-a-matrix-with-conditions | Topo_sort || python | topo_sort-python-by-viishhnu-kdnr | Intuition\n Describe your first thoughts on how to solve this problem. \n1)concept is to find topo_sort for row and col...\n2)iterate from topo_sort of row elem | viishhnu | NORMAL | 2023-08-28T03:06:27.988623+00:00 | 2023-08-28T03:06:27.988645+00:00 | 104 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1)concept is to find topo_sort for row and col...\n2)iterate from topo_sort of row elements and find its corresponding pos in topo_sort of col\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time ... | 2 | 0 | ['Python3'] | 1 |
build-a-matrix-with-conditions | C++ Basic Topological Sort Approach | c-basic-topological-sort-approach-by-dav-xuk0 | Intuition\n Describe your first thoughts on how to solve this problem. \nIn this problem we are given \'k\' number of elements that is 1 through k\nalong with t | david_makhija | NORMAL | 2023-07-05T06:16:53.615545+00:00 | 2023-07-05T06:16:53.615582+00:00 | 45 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIn this problem we are given \'k\' number of elements that is 1 through k\nalong with the relative order between some of the elements\nthe order is given in two formats that is row-wise and column-wise which we need to maintain in the res... | 2 | 0 | ['Depth-First Search', 'Graph', 'Topological Sort', 'Matrix', 'C++'] | 1 |
build-a-matrix-with-conditions | TopoSort | toposort-by-recursive45-2jpm | \n\n# Code\n\nclass Solution {\npublic:\n vector<vector<int>> buildMatrix(int k, vector<vector<int>> &rowConditions, vector<vector<int>> &colConditions)\ | Recursive45 | NORMAL | 2023-06-05T13:47:49.801340+00:00 | 2023-06-05T13:47:49.801381+00:00 | 225 | false | \n\n# Code\n```\nclass Solution {\npublic:\n vector<vector<int>> buildMatrix(int k, vector<vector<int>> &rowConditions, vector<vector<int>> &colConditions)\n{\n vector<int> adj1[k], adj2[k];\n vector<int> indegree1(k, 0), indegree2(k, 0);\n for (auto it : rowConditions)\n {\n int u = it[0] - 1... | 2 | 0 | ['C++'] | 2 |
build-a-matrix-with-conditions | [Python 3] Topological Sorting | python-3-topological-sorting-by-bereket_-wiua | \n\n\n```\n\ndef buildMatrix(self, k: int, rowConditions: List[List[int]], colConditions: List[List[int]]) -> List[List[int]]:\n ans = [[0] * k for _ in | Bereket_sh | NORMAL | 2023-05-13T19:01:56.324203+00:00 | 2023-05-13T19:16:37.293953+00:00 | 555 | false | \n\n\n```\n\ndef buildMatrix(self, k: int, rowConditions: List[List[int]], colConditions: List[List[int]]) -> List[List[int]]:\n ans = [[0] * k for _ in range(k)]\n\t\t\n def topological(condition):\n graph = defaultdict(list)\n indegree = [0] * k\n for a, b in condition:\... | 2 | 0 | ['Topological Sort', 'Python3'] | 1 |
build-a-matrix-with-conditions | c++ | easy to undersatand | step by step | c-easy-to-undersatand-step-by-step-by-ve-4cws | ```\nclass Solution {\n vector top_sorting(vector> con, int k) {\n vector indegree(k+1, 0);\n vector> graph(k+1);\n for(auto &it: con) { | venomhighs7 | NORMAL | 2022-09-27T12:13:39.838741+00:00 | 2022-09-27T12:13:39.838779+00:00 | 96 | false | ```\nclass Solution {\n vector<int> top_sorting(vector<vector<int>> con, int k) {\n vector<int> indegree(k+1, 0);\n vector<vector<int>> graph(k+1);\n for(auto &it: con) {\n indegree[it[1]] += 1;\n graph[it[0]].push_back(it[1]);\n }\n \n vector<int> ans;... | 2 | 0 | [] | 0 |
build-a-matrix-with-conditions | ✅✅Faster || Easy To Understand || C++ Code | faster-easy-to-understand-c-code-by-__kr-4k9o | Using Topological Sort With BFS\n\n Time Complexity :- O(V + E)\n\n Space Complexity :- O(V + E)\n\n\nclass Solution {\npublic:\n \n // function for findi | __KR_SHANU_IITG | NORMAL | 2022-09-01T11:27:19.754188+00:00 | 2022-09-01T11:27:19.754231+00:00 | 274 | false | * ***Using Topological Sort With BFS***\n\n* ***Time Complexity :- O(V + E)***\n\n* ***Space Complexity :- O(V + E)***\n\n```\nclass Solution {\npublic:\n \n // function for finding toposort of a graph\n \n vector<int> toposort(vector<vector<int>> adj)\n {\n int V = adj.size();\n \n ... | 2 | 0 | ['Breadth-First Search', 'Graph', 'Topological Sort', 'C', 'C++'] | 1 |
build-a-matrix-with-conditions | C++ | Topological sort | 100% Faster, 0ms | Easy Code to follow | c-topological-sort-100-faster-0ms-easy-c-dna9 | Please Upvote :)\n\n\nclass Solution {\npublic:\n vector<vector<int>> buildMatrix(int k, vector<vector<int>>& rowConditions, vector<vector<int>>& colConditio | ankit4601 | NORMAL | 2022-08-29T16:18:39.250779+00:00 | 2022-08-29T16:18:39.250816+00:00 | 231 | false | Please Upvote :)\n\n```\nclass Solution {\npublic:\n vector<vector<int>> buildMatrix(int k, vector<vector<int>>& rowConditions, vector<vector<int>>& colConditions) {\n vector<vector<int>> v(k,vector<int>(k,0));\n auto p=topo(rowConditions,k);\n auto q=topo(colConditions,k);\n if(p.size()=... | 2 | 0 | ['Depth-First Search', 'Graph', 'Topological Sort', 'C', 'C++'] | 2 |
build-a-matrix-with-conditions | ✅C++|| Kahn's Algo || Topological Sort || Beginner friendly | c-kahns-algo-topological-sort-beginner-f-e2l7 | \nclass Solution {\npublic:\n vector<int> kahn(vector<vector<int>>conditions, int k)\n {\n vector<int>graph[k+1];\n vector<int>degree(k+1,0) | indresh149 | NORMAL | 2022-08-29T07:49:59.871538+00:00 | 2022-08-29T07:49:59.871764+00:00 | 59 | false | ```\nclass Solution {\npublic:\n vector<int> kahn(vector<vector<int>>conditions, int k)\n {\n vector<int>graph[k+1];\n vector<int>degree(k+1,0);\n vector<int>ans;\n queue<int>q;\n for(vector<int>condition : conditions)\n {\n graph[condition[0]].push_back(condit... | 2 | 0 | ['Topological Sort', 'C'] | 0 |
build-a-matrix-with-conditions | Kotlin Topological Sort | Kahn's Algorithm | kotlin-topological-sort-kahns-algorithm-bgdcj | \nclass Solution {\n data class Node (var `val`: Int, val `in`: MutableList<Int>, val `out`: MutableList<Int>)\n fun buildMatrix(k: Int, rowConditions: Ar | Z3ROsum | NORMAL | 2022-08-29T04:37:15.967053+00:00 | 2022-08-29T04:37:15.967088+00:00 | 82 | false | ```\nclass Solution {\n data class Node (var `val`: Int, val `in`: MutableList<Int>, val `out`: MutableList<Int>)\n fun buildMatrix(k: Int, rowConditions: Array<IntArray>, colConditions: Array<IntArray>): Array<IntArray> {\n var rowSorted = listOf<Int>()\n var colSorted = listOf<Int>()\n for ... | 2 | 0 | ['Topological Sort', 'Kotlin'] | 0 |
build-a-matrix-with-conditions | Step by Step Approach | Easy to Follow | C++ Implementation | step-by-step-approach-easy-to-follow-c-i-48ku | Here is an explanation from post contest discussion meeting.\n\nhttps://www.youtube.com/watch?v=LDNMlgBi5vg&list=PLQ9cQ3JqeqU_T-Ic3384j4uWDxUnXjlVO&index=4 | sandywadhwa | NORMAL | 2022-08-28T16:28:52.337219+00:00 | 2022-08-28T16:28:52.337251+00:00 | 26 | false | Here is an explanation from post contest discussion meeting.\n\nhttps://www.youtube.com/watch?v=LDNMlgBi5vg&list=PLQ9cQ3JqeqU_T-Ic3384j4uWDxUnXjlVO&index=4 | 2 | 0 | [] | 0 |
build-a-matrix-with-conditions | C++ Graph Solution | c-graph-solution-by-travanj05-8cu0 | cpp\nint rowIdx[500], colIdx[500];\n\nclass Solution {\npublic:\n vector<vector<int>> buildMatrix(int k, vector<vector<int>> &rowConditions, vector<vector<in | travanj05 | NORMAL | 2022-08-28T06:15:33.346422+00:00 | 2022-08-28T06:15:33.346464+00:00 | 53 | false | ```cpp\nint rowIdx[500], colIdx[500];\n\nclass Solution {\npublic:\n vector<vector<int>> buildMatrix(int k, vector<vector<int>> &rowConditions, vector<vector<int>> &colConditions) {\n int n = rowConditions.size(), m = colConditions.size();\n fill(rowIdx, rowIdx + k + 1, 0);\n fill(colIdx, colIdx... | 2 | 0 | ['Graph', 'C', 'C++'] | 1 |
build-a-matrix-with-conditions | C++ - Quick Explained Code - Topo Sort, Kahn's Algo | c-quick-explained-code-topo-sort-kahns-a-vy4b | Thought Process:\n This is an interesting problem, specially to see how graph helps solve this.\n Reading the problem with the rowConditions and columnCondition | geekykant | NORMAL | 2022-08-28T05:18:17.898189+00:00 | 2022-08-28T05:23:36.391181+00:00 | 98 | false | **Thought Process:**\n* This is an interesting problem, specially to see how graph helps solve this.\n* Reading the problem with the `rowConditions` and `columnConditions` does give the hint that applying topological sort would make sense here.\n* So we do the topo sort, and sparsely set the index across columns. Toget... | 2 | 0 | ['Graph', 'Topological Sort', 'C'] | 0 |
build-a-matrix-with-conditions | C# Solution | Graph, BFS | c-solution-graph-bfs-by-tonytroeff-g3bh | C#\npublic class Solution {\n public int[][] BuildMatrix(int k, int[][] rowConditions, int[][] colConditions) {\n Dictionary<int, HashSet<int>> rowMap | tonytroeff | NORMAL | 2022-08-28T05:10:52.567740+00:00 | 2022-08-28T05:10:52.567794+00:00 | 29 | false | ```C#\npublic class Solution {\n public int[][] BuildMatrix(int k, int[][] rowConditions, int[][] colConditions) {\n Dictionary<int, HashSet<int>> rowMap = new (), rowDepsMap = new (), colMap = new (), colDepsMap = new ();\n for (int i = 0; i < k; i++)\n {\n rowMap[i] = new ();\n ... | 2 | 0 | ['Breadth-First Search', 'Graph'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.