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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
find-elements-in-a-contaminated-binary-tree | C# Suii | c-suii-by-rhazem13-v1k5 | \npublic class FindElements {\n public TreeNode myroot;\n public FindElements(TreeNode root) {\n this.myroot=root;\n root.val=0;\n tr | rhazem13 | NORMAL | 2023-10-29T11:50:42.640550+00:00 | 2023-10-29T11:50:42.640567+00:00 | 13 | false | ```\npublic class FindElements {\n public TreeNode myroot;\n public FindElements(TreeNode root) {\n this.myroot=root;\n root.val=0;\n traverse(root);\n }\n public void traverse(TreeNode root){\n if(root==null)return;\n if(root.left!=null){\n root.left.val=2*root... | 2 | 0 | [] | 0 |
find-elements-in-a-contaminated-binary-tree | Easy Java Solution | easy-java-solution-by-ravikumar50-49yq | 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 | ravikumar50 | NORMAL | 2023-09-19T06:57:53.025937+00:00 | 2023-09-19T06:57:53.025961+00:00 | 244 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 2 | 0 | ['Java'] | 0 |
find-elements-in-a-contaminated-binary-tree | BFS(Level Order Traversal) , C++ ✅✅ | bfslevel-order-traversal-c-by-deepak_591-wkmm | Approach\n Describe your approach to solving the problem. \nUse BFS (Level Order Traversal Format) to assign values to the nodes and store them in an unordered | Deepak_5910 | NORMAL | 2023-07-13T10:17:06.863902+00:00 | 2023-07-23T17:14:20.147101+00:00 | 152 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nUse **BFS (Level Order Traversal Format)** to assign values to the nodes and store them in an **unordered map** to return the answer in **O(1) time** in the **find() function**.\n\n# Complexity\n- Time complexity:O(N)\n<!-- Add your time complexity he... | 2 | 0 | ['Tree', 'Breadth-First Search', 'C++'] | 1 |
find-elements-in-a-contaminated-binary-tree | Simple DFS Solution || Beats others | simple-dfs-solution-beats-others-by-shri-ngth | \n\n# Code\n\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNod | Shristha | NORMAL | 2023-01-22T13:39:40.169024+00:00 | 2023-01-22T13:39:40.169072+00:00 | 289 | false | \n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, Tre... | 2 | 0 | ['Depth-First Search', 'C++'] | 0 |
find-elements-in-a-contaminated-binary-tree | easy understading and memory efficient solution in js | easy-understading-and-memory-efficient-s-rnhi | ```\nvar FindElements = function(root) {\n this.tree = root\n};\n\n/ \n * @param {number} target\n * @return {boolean}\n /\nFindElements.prototype.find = fun | HabibovUlugbek | NORMAL | 2023-01-20T10:10:58.534551+00:00 | 2023-01-20T10:10:58.534602+00:00 | 160 | false | ```\nvar FindElements = function(root) {\n this.tree = root\n};\n\n/** \n * @param {number} target\n * @return {boolean}\n */\nFindElements.prototype.find = function(target) {\n this.tree.val = 0;\n function find(target,root){\n if(!root) return false;\n let val = root.val\n if(val === tar... | 2 | 0 | ['Tree', 'JavaScript'] | 0 |
find-elements-in-a-contaminated-binary-tree | C++ || Array and Tree ✅ || Easiest Approach 🔥 | c-array-and-tree-easiest-approach-by-ujj-qeyh | \n# Approach\nForming a array to store binary tree. The values that is asked to store is similar to index that we use to store element of tree in array. Only st | UjjwalAgrawal | NORMAL | 2023-01-04T16:01:03.764863+00:00 | 2023-01-04T16:02:01.304240+00:00 | 370 | false | \n# Approach\nForming a array to store binary tree. The values that is asked to store is similar to index that we use to store element of tree in array. Only storing a tree will take O(n). Otherwise find function will take O(1) time as it is only checking whether at target value, i.e., same as index of array is -1 or n... | 2 | 0 | ['Tree', 'Depth-First Search', 'C++'] | 0 |
find-elements-in-a-contaminated-binary-tree | Java Easy Solution using HashSet | java-easy-solution-using-hashset-by-avad-afuo | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nSave all the nodes value in HashSet\n Describe your approach to solving t | avadarshverma737 | NORMAL | 2022-11-15T05:47:21.294297+00:00 | 2022-11-15T05:47:21.294342+00:00 | 340 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nSave all the nodes value in HashSet\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... | 2 | 0 | ['Hash Table', 'Java'] | 0 |
find-elements-in-a-contaminated-binary-tree | Go with map | go-with-map-by-tuanbieber-k26b | \ntype FindElements struct {\n m map[int]struct{}\n}\n\nfunc Constructor(root *TreeNode) FindElements {\n m := make(map[int]struct{})\n \n var recov | tuanbieber | NORMAL | 2022-07-16T15:14:06.122235+00:00 | 2022-07-16T15:14:06.122267+00:00 | 106 | false | ```\ntype FindElements struct {\n m map[int]struct{}\n}\n\nfunc Constructor(root *TreeNode) FindElements {\n m := make(map[int]struct{})\n \n var recoverTree func(*TreeNode, int)\n recoverTree = func(root *TreeNode, val int) {\n if root == nil {\n return\n }\n \n m... | 2 | 0 | ['Recursion', 'Go'] | 0 |
find-elements-in-a-contaminated-binary-tree | C++: Easy and Concise | c-easy-and-concise-by-abhijeet_26-0u68 | \nclass FindElements {\nprivate:\n unordered_set<int>st;\n void makeTree(TreeNode* root,int data)\n {\n if(!root) return;\n root->val=dat | abhijeet_26 | NORMAL | 2022-01-19T14:34:35.447076+00:00 | 2022-01-19T14:34:35.447114+00:00 | 162 | false | ```\nclass FindElements {\nprivate:\n unordered_set<int>st;\n void makeTree(TreeNode* root,int data)\n {\n if(!root) return;\n root->val=data;\n st.insert(data);\n makeTree(root->left,(data*2+1));\n makeTree(root->right,(data*2+2));\n \n }\n \npublic:\n Fi... | 2 | 0 | ['Recursion', 'C', 'Ordered Set', 'C++'] | 0 |
find-elements-in-a-contaminated-binary-tree | C++ Easy To Implementation | c-easy-to-implementation-by-beast_vin-r2uy | class FindElements {\npublic:\n\n sets;\n void solve(TreeNode root)\n {\n if(root)\n {\n int x=root->val;\n i | beast_vin | NORMAL | 2021-12-14T11:08:37.619762+00:00 | 2021-12-14T11:08:37.619804+00:00 | 103 | false | class FindElements {\npublic:\n\n set<int>s;\n void solve(TreeNode *root)\n {\n if(root)\n {\n int x=root->val;\n if(root->left)\n {\n root->left->val=2*x+1;\n s.insert(2*x+1);\n solve(root->left);\n }\n... | 2 | 0 | ['Depth-First Search', 'Recursion', 'C', 'Ordered Set'] | 0 |
find-elements-in-a-contaminated-binary-tree | C++ || EASY MAP | c-easy-map-by-the_expandable-b7vm | ```\n/\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() : val(0), | the_expandable | NORMAL | 2021-12-13T09:09:49.967086+00:00 | 2021-12-13T09:09:49.967113+00:00 | 62 | false | ```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right... | 2 | 0 | [] | 0 |
find-elements-in-a-contaminated-binary-tree | C++ || 99% faster || Simple DFS | c-99-faster-simple-dfs-by-_blackdev-1x9i | ```\nclass FindElements {\npublic:\n vector mapper;\n FindElements(TreeNode root) {\n mapper.resize(1000005,false);\n filterThis(root,0);\n | _BlackDev | NORMAL | 2021-07-26T10:27:26.869612+00:00 | 2021-07-26T10:27:26.869654+00:00 | 96 | false | ```\nclass FindElements {\npublic:\n vector<bool> mapper;\n FindElements(TreeNode* root) {\n mapper.resize(1000005,false);\n filterThis(root,0);\n }\n void filterThis(TreeNode* root, int x) {\n if(!root) return;\n if(x<=1000001) {\n mapper[x] = true; \n filt... | 2 | 0 | [] | 1 |
find-elements-in-a-contaminated-binary-tree | O(1) find Operation Approach 🔥 | o1-find-operation-approach-by-faisalalik-u1hu | \tclass FindElements {\n\tpublic:\n bool arr[2097152]={false}; // it is stated that max height of tree is less than 20,\n\t//so max nodes will be 2^height+1\ | faisalalik9 | NORMAL | 2021-06-30T12:20:49.650048+00:00 | 2021-06-30T12:20:49.650080+00:00 | 86 | false | \tclass FindElements {\n\tpublic:\n bool arr[2097152]={false}; // it is stated that max height of tree is less than 20,\n\t//so max nodes will be 2^height+1\n\t\n FindElements(TreeNode* root) {\n cure(root,0);\n }\n void cure(TreeNode* root,int i){\n if(root==NULL)\n return;\n ... | 2 | 2 | [] | 0 |
find-elements-in-a-contaminated-binary-tree | [C++] No HashMap, Bit Path | c-no-hashmap-bit-path-by-ieasons-vy9o | idea: Use a stack to store the bit path and then reversely find.\n\nclass FindElements {\npublic:\n FindElements(TreeNode* root) {\n r = root;\n | ieasons | NORMAL | 2020-01-21T03:51:13.895139+00:00 | 2020-01-21T03:51:13.895172+00:00 | 284 | false | idea: Use a stack to store the bit path and then reversely find.\n```\nclass FindElements {\npublic:\n FindElements(TreeNode* root) {\n r = root;\n if (!root) return;\n build(root, 0);\n }\n \n bool find(int target) {\n stack<bool> st;\n int t = target;\n while (t >... | 2 | 1 | [] | 0 |
minimum-initial-energy-to-finish-tasks | [Python] clean greedy solution with explanation | python-clean-greedy-solution-with-explan-ktk7 | Idea\n\nFor task = [cost, mmin], it needs mmin energy to start but only needs cost energy to finish. Let\'s define mmin - cost as the energy saved for this task | alanlzl | NORMAL | 2020-11-22T04:00:57.785106+00:00 | 2020-11-22T04:11:25.707079+00:00 | 6,171 | false | **Idea**\n\nFor `task = [cost, mmin]`, it needs `mmin` energy to start but only needs `cost` energy to finish. Let\'s define `mmin - cost` as the energy `saved` for this task.\n\nTo start a new task, we need to add `mmin - prev_saved` energy. Therefore, we want to complete the tasks with higher `saved` first so as to m... | 125 | 3 | [] | 20 |
minimum-initial-energy-to-finish-tasks | [Java/C++/Python] Sort, and some story | javacpython-sort-and-some-story-by-lee21-0hjg | Intuition\nNeed to sort by minimum - actual\n\n\n# Explanation\nWe have n investor,\neach investor can invest actual energy,\nand he think your company have min | lee215 | NORMAL | 2020-11-22T04:05:01.023040+00:00 | 2020-11-29T09:43:40.512534+00:00 | 8,163 | false | # Intuition\nNeed to sort by `minimum - actual`\n<br>\n\n# Explanation\nWe have `n` investor,\neach investor can invest `actual` energy,\nand he think your company have `minimum` value.\n\nIf you already have at least `minimum - actual` energy,\nthe investory will invest you `actual` energy.\n\nAssuming you get all inv... | 119 | 6 | [] | 17 |
minimum-initial-energy-to-finish-tasks | // Easy Code with Comments - Sort and Borrow energy when necessary | easy-code-with-comments-sort-and-borrow-odcx9 | \n// Easy Code with Comments - Sort and Borrow energy when necessary\n\n\n// a[1] & b[1] are minimum energies while\n// a[0] & b[0] are actual energies required | interviewrecipes | NORMAL | 2020-11-22T04:01:44.655886+00:00 | 2020-11-22T04:03:11.351444+00:00 | 2,695 | false | ```\n// Easy Code with Comments - Sort and Borrow energy when necessary\n\n\n// a[1] & b[1] are minimum energies while\n// a[0] & b[0] are actual energies required.\n// Sort the array in the descending order of (minimum - actual).\n// (minimum - actual) is the amount of energy that remains after \n// finishing a task. ... | 97 | 0 | [] | 10 |
minimum-initial-energy-to-finish-tasks | A real strategy to invest | a-real-strategy-to-invest-by-chipbk10-g0mi | If you want to invest on a project [x,y], you must have y money. Once finished, you gain y-x money. So, which project you should invest first to build up a good | chipbk10 | NORMAL | 2020-11-23T13:38:09.490761+00:00 | 2020-11-24T11:06:54.873477+00:00 | 1,375 | false | If you want to invest on a project `[x,y]`, you must have `y` money. Once finished, you gain `y-x` money. So, which project you should invest first to build up a good capital for the next investments?\n\nMy advice is to invest on projects which are able to bring back the highest profitability `y-x`. Even, in the case `... | 43 | 1 | [] | 3 |
minimum-initial-energy-to-finish-tasks | Explanation on why sort by difference | explanation-on-why-sort-by-difference-by-g98d | Intuition\n\nSort by the difference mininum - actual and then process one by one.\n\nHow to come up with intuition\n\nObserve the examples.\nThe most important | mengmamax | NORMAL | 2020-11-22T04:41:15.794364+00:00 | 2020-11-22T10:49:39.526483+00:00 | 1,961 | false | **Intuition**\n\nSort by the difference `mininum - actual` and then process one by one.\n\n**How to come up with intuition**\n\nObserve the examples.\nThe most important thing after receiving a problem is to understand it.\nHere understand means not only reading the text, but also going through the examples.\nOne can f... | 28 | 2 | [] | 7 |
minimum-initial-energy-to-finish-tasks | [Java] - BST pattern - same Leetcode problems and Greedy Idea - 100% | java-bst-pattern-same-leetcode-problems-v71f5 | Idea 1: BST \n\nHow can we break this issue into a smaller problem? \nThink about this :\n\n What is the minimum potential result can it be ? --> min = sum of a | tea_93 | NORMAL | 2020-11-22T04:08:23.679950+00:00 | 2020-11-25T05:04:41.933572+00:00 | 1,396 | false | **Idea 1: BST **\n\nHow can we break this issue into a smaller problem? \nThink about this :\n\n* What is the minimum potential result can it be ? --> min = sum of all task[0]\n* What is the maximum potential result can it be ? --> max = sum of all ( task[0] + task[1] )\n\n If result is a number (X). is X a valid numbe... | 20 | 0 | [] | 5 |
minimum-initial-energy-to-finish-tasks | C++ Sort by [Minimum - Actual] | c-sort-by-minimum-actual-by-votrubac-4a5s | The idea is to first do tasks with the largest difference between required and consumed energy.\n \nThus, we sort the tasks, and then just track the energy r | votrubac | NORMAL | 2020-11-22T04:13:47.607965+00:00 | 2020-11-22T04:13:47.608007+00:00 | 1,724 | false | The idea is to first do tasks with the largest difference between required and consumed energy.\n \nThus, we sort the tasks, and then just track the energy requried.\n\n```cpp\nint minimumEffort(vector<vector<int>>& tasks) {\n int energy = 0, res = 0;\n sort(begin(tasks), end(tasks), [](vector<int> &t1, vector... | 19 | 3 | [] | 5 |
minimum-initial-energy-to-finish-tasks | [Python] Greedy solution with intuition and proof | python-greedy-solution-with-intuition-an-5u2f | The code to the greedy approach is relatively straightforward. However what makes it hard is actually proving that the greedy approach is correct.\n\nIntuition: | algomelon | NORMAL | 2020-11-24T00:36:43.237079+00:00 | 2020-11-24T18:40:51.019488+00:00 | 595 | false | The code to the greedy approach is relatively straightforward. However what makes it hard is actually proving that the greedy approach is correct.\n\nIntuition:\nEach time we process a task, we\'ll have some energy left over that we can carry forward onto the next task. Ideally we\'d then want to carry as much as possi... | 16 | 0 | [] | 2 |
minimum-initial-energy-to-finish-tasks | C++ | easy solution using sorting | c-easy-solution-using-sorting-by-sekhar1-r4cv | https://www.youtube.com/watch?v=CgaYzm3s1SU\n\nThe minimum energy required will be >= total energy of all tasks + some additional energy required for the tasks | sekhar179 | NORMAL | 2020-11-28T17:01:19.287095+00:00 | 2020-11-29T12:15:32.484552+00:00 | 612 | false | https://www.youtube.com/watch?v=CgaYzm3s1SU\n\nThe minimum energy required will be >= total energy of all tasks + some additional energy required for the tasks having "minimum energy" requirement >= actual energy requirement.\nso "total enery of all tasks" <= answer <= "total minimum energy of all tasks"\nKey points:\n... | 8 | 0 | ['C'] | 2 |
minimum-initial-energy-to-finish-tasks | C++ Understandable Solution | c-understandable-solution-by-sairakesh-uh1f | Just add the total actual energy\'s required to get all done, and the minimum difference between the actual and minimum energy required to kick start the proces | sairakesh | NORMAL | 2020-11-22T04:19:55.867014+00:00 | 2020-11-23T10:15:52.937423+00:00 | 722 | false | * Just add the total actual energy\'s required to get all done, and the minimum difference between the actual and minimum energy required to kick start the process.\n* Another case is where the minimum energy required could be very high, thus we find the maximum of the required energies.\n* Now we return the maximum of... | 8 | 2 | ['C'] | 3 |
minimum-initial-energy-to-finish-tasks | [C++] Greedy Solution Simple and Clear Explanation | c-greedy-solution-simple-and-clear-expla-3uec | Let\'s break the problem into two parts:\n1. Ordering the tasks\n2. Calculating the tasks\n\n1. Ordering the tasks\n\nIntuition:\nConsider a particular task, wh | arnabsen1729 | NORMAL | 2020-11-22T04:37:26.474507+00:00 | 2020-11-22T04:47:17.955929+00:00 | 442 | false | Let\'s break the problem into two parts:\n1. Ordering the tasks\n2. Calculating the tasks\n\n**1. Ordering the tasks**\n\n**Intuition:**\nConsider a particular task, which has `A` actual energy required and `M` minimum energy required. So, in order to complete this task we need to provide atleast `M` energy. But `M-A` ... | 5 | 0 | ['Greedy', 'Sorting'] | 2 |
minimum-initial-energy-to-finish-tasks | Python 3 | Sort + Greedy & Sort + Binary Search | Explanation | python-3-sort-greedy-sort-binary-search-uw5fj | Approach \#1 - Binary Search\n- Sort by difference\n- Use binary search validate if given input (energy) can finish all works\n- Search the smallest possible (l | idontknoooo | NORMAL | 2020-11-22T05:42:41.184171+00:00 | 2020-11-22T05:42:41.184213+00:00 | 470 | false | ### Approach \\#1 - Binary Search\n- Sort by difference\n- Use binary search validate if given input (energy) can finish all works\n- Search the smallest possible (like `bisect_left`)\n```\nclass Solution:\n def minimumEffort(self, tasks: List[List[int]]) -> int:\n tasks.sort(key=lambda x: x[0]-x[1])\n ... | 4 | 0 | ['Binary Search', 'Greedy', 'Python', 'Python3'] | 1 |
minimum-initial-energy-to-finish-tasks | C++ | Beast 100% | Explained Properly | Simple Binary Search | c-beast-100-explained-properly-simple-bi-11sq | IntuitionThe goal is to find the smallest amount of energy to start with so that you can complete all tasks in some order.The key idea is:
Some tasks are harder | AK200199 | NORMAL | 2025-03-24T21:05:04.259396+00:00 | 2025-03-24T21:05:04.259396+00:00 | 34 | false | # Intuition
The goal is to find the smallest amount of energy to start with so that you can complete all tasks in some order.
The key idea is:
Some tasks are harder to start (high minimum) but don’t cost much (actual).
These tasks should be done earlier, while you still have enough energy.
# Approach
1.)Sort the task... | 3 | 0 | ['Array', 'Binary Search', 'Sorting', 'C++'] | 0 |
minimum-initial-energy-to-finish-tasks | Greedy with Formal proof of correctness | greedy-with-formal-proof-of-correctness-e4wgf | As many of you may have found out the greedy strategy of doing those tasks first which have maximum minimum_{i} - actual_{i} yields the optimal solution, but wh | sanky29 | NORMAL | 2022-12-23T19:40:08.926565+00:00 | 2022-12-24T13:47:38.503881+00:00 | 610 | false | As many of you may have found out the greedy strategy of doing those tasks first which have maximum $$minimum_{i} - actual_{i}$$ yields the optimal solution, but why?\n\nWhen we start to solve the questions we try to find some pattern in it and see if dynamic programming, divide and conquer, backtracking, etc. will wor... | 3 | 0 | ['C++'] | 2 |
minimum-initial-energy-to-finish-tasks | JAVA | java-by-lankesh-rhoc | This question revolves around finding minimum cost to complete all the task\nWe we will use the idea of sorting according to difference of Minimum - actual\nin | lankesh | NORMAL | 2022-01-08T07:20:43.866837+00:00 | 2022-01-08T07:20:43.866870+00:00 | 395 | false | This question revolves around finding minimum cost to complete all the task\nWe we will use the idea of sorting according to difference of ```Minimum - actual```\nin Descending order. \nThis will help us in setting the initial value for energy required in such \na way that left over after using the energy can be used f... | 3 | 0 | ['Java'] | 1 |
minimum-initial-energy-to-finish-tasks | Greedy Algorithm with FULL and EASY Explanation with NO fancy ideas or concepts!!!!! | greedy-algorithm-with-full-and-easy-expl-0wg4 | The most critical part of greedy algorithm is why we sort the array by its minimum - cost (that is tasks[i][1] - tasks[i][0]) value? If people understand this t | yuandong-chen | NORMAL | 2020-11-27T19:44:50.604609+00:00 | 2020-11-29T01:01:49.052622+00:00 | 588 | false | The most critical part of greedy algorithm is why we sort the array by its `minimum - cost (that is tasks[i][1] - tasks[i][0])` value? If people understand this trick, the leftover is nothing but iteration. \n\nFirstly, please read the question **course scheduler III**: https://leetcode.com/problems/course-schedule-iii... | 3 | 0 | [] | 0 |
minimum-initial-energy-to-finish-tasks | [Python] Greedy, sort first by gap, then by required start energy | python-greedy-sort-first-by-gap-then-by-7w4ze | Not exactly sure why this works, but we know that we probably want to do the tasks with small gaps last, and the tasks with the largest required start energy fi | raymondhfeng | NORMAL | 2020-11-22T04:01:40.553189+00:00 | 2020-11-22T04:01:40.553230+00:00 | 327 | false | Not exactly sure why this works, but we know that we probably want to do the tasks with small gaps last, and the tasks with the largest required start energy first. \n\n```\nclass Solution:\n def minimumEffort(self, tasks: List[List[int]]) -> int:\n tasks.sort(key = lambda x: (-(x[1]-x[0]),-x[1]))\n cu... | 3 | 0 | [] | 0 |
minimum-initial-energy-to-finish-tasks | C++ | greedy solution with Intution for sorting | c-greedy-solution-with-intution-for-sort-x9fw | Intuition1st Intution :After observation, I take the sum of all the the actual time, then one by one check for each task the answer, if we take the task in last | UKS_28 | NORMAL | 2025-01-16T03:49:19.465778+00:00 | 2025-01-16T03:49:19.465778+00:00 | 104 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
### 1st Intution :
After observation, I take the sum of all the the actual time, then one by one check for each task the answer, if we take the task in last. If we take a task_i in last then we will not take the actual_time[i] of that task ... | 2 | 0 | ['Greedy', 'Sorting', 'C++'] | 0 |
minimum-initial-energy-to-finish-tasks | Easy C++ solution || Greedy Approach | easy-c-solution-greedy-approach-by-bhara-nqij | \n\n# Code\n\nclass Solution {\npublic:\n static bool cmp(vector<int>& a, vector<int>& b){\n return (a[1] - a[0]) > (b[1] - b[0]);\n }\n\n int m | bharathgowda29 | NORMAL | 2024-01-04T07:38:20.042119+00:00 | 2024-01-04T07:38:20.042140+00:00 | 255 | false | \n\n# Code\n```\nclass Solution {\npublic:\n static bool cmp(vector<int>& a, vector<int>& b){\n return (a[1] - a[0]) > (b[1] - b[0]);\n }\n\n int minimumEffort(vector<vector<int>>& tasks) {\n sort(tasks.begin(), tasks.end(), cmp);\n int n = tasks.size(), ans = 0, energyLeft = 0;\n f... | 2 | 0 | ['Array', 'Greedy', 'Sorting', 'C++'] | 0 |
minimum-initial-energy-to-finish-tasks | ✔️✔️[C++] Explained using Priority queue Simple solution | c-explained-using-priority-queue-simple-9utr7 | \nstruct Compare {\n bool operator()(pair<int,int> &a, pair<int,int> &b){\n return a.first-a.second < b.first-b.second;\n }\n};\n\nclass Solution { | am_aakash | NORMAL | 2023-02-04T13:02:58.584281+00:00 | 2023-02-04T13:02:58.584317+00:00 | 341 | false | ```\nstruct Compare {\n bool operator()(pair<int,int> &a, pair<int,int> &b){\n return a.first-a.second < b.first-b.second;\n }\n};\n\nclass Solution {\npublic:\n int minimumEffort(vector<vector<int>>& tasks) {\n priority_queue<pair<int,int>, vector<pair<int,int>>, Compare> pq;\n // sorted ... | 2 | 0 | ['Greedy', 'Heap (Priority Queue)', 'C++'] | 0 |
minimum-initial-energy-to-finish-tasks | Sort + memoization C++ using greedy approach | sort-memoization-c-using-greedy-approach-oam0 | Intuition\n- We need to prioritise doing tasks first which has higher difference actual and minimum energy. \n- Because they have high barrier (minimum energy) | him500 | NORMAL | 2022-12-25T12:54:05.709126+00:00 | 2022-12-25T12:54:05.709161+00:00 | 499 | false | # Intuition\n- We need to prioritise doing tasks first which has higher difference actual and minimum energy. \n- Because they have high barrier (minimum energy) but low actual energy as compared to min energy so we need to prioritise them. \n- One way is to sort them by their difference.\n\n# Complexity\n- Time comple... | 2 | 0 | ['Dynamic Programming', 'Greedy', 'Memoization', 'C++'] | 1 |
minimum-initial-energy-to-finish-tasks | Greedy solution, sorting | greedy-solution-sorting-by-prashant18253-sf3x | Sort the array on the basis of the difference between the threshold and actual energy.\n\nimport java.util.*;\nclass Solution {\n public int minimumEffort(in | prashant18253 | NORMAL | 2021-06-27T09:01:51.429179+00:00 | 2021-06-27T09:01:51.429213+00:00 | 238 | false | Sort the array on the basis of the difference between the threshold and actual energy.\n```\nimport java.util.*;\nclass Solution {\n public int minimumEffort(int[][] tasks)\n {\n Arrays.sort(tasks, new Comparator<int[]>(){\n @Override\n public int compare(int[] a, int[] b)\n ... | 2 | 0 | ['Sorting', 'Java'] | 0 |
minimum-initial-energy-to-finish-tasks | Proof of the greedy approach | proof-of-the-greedy-approach-by-wutongth-nbu9 | Suppose the energe we have before starting is E, and the order of the taskes is (a[0], m[0]), ... (a[n-1], m[n-1])\n\nE should satisfy the following rules:\n\nE | wutongthucs | NORMAL | 2021-03-28T22:18:21.761516+00:00 | 2021-03-28T22:30:37.001039+00:00 | 205 | false | Suppose the energe we have before starting is E, and the order of the taskes is ```(a[0], m[0]), ... (a[n-1], m[n-1])```\n\nE should satisfy the following rules:\n```\nE >= m[0],\nE >= a[0] + m[1],\n...\nE >= sum(a[0:i)) + m[i]\n...\n```\n\nLet ```c[i] = sum(a[0:i)) + m[i]```, we would have ```E >= max(c[0], c[1],.... ... | 2 | 0 | [] | 2 |
minimum-initial-energy-to-finish-tasks | Java - with simple idea explanation | java-with-simple-idea-explanation-by-xyb-k37z | \nclass Solution {\n public int minimumEffort(int[][] tasks) {\n \n /*\n Idea - finding the minimum initial energy to finish tasks\n | xyborg | NORMAL | 2021-01-01T13:26:40.387560+00:00 | 2021-01-01T13:27:08.959945+00:00 | 263 | false | ```\nclass Solution {\n public int minimumEffort(int[][] tasks) {\n \n /*\n Idea - finding the minimum initial energy to finish tasks\n \n -> finish tasks which can induce max residual energy after completion\n eg - [5,10] over [10,10] since former can carry over energy\n ... | 2 | 0 | ['Java'] | 0 |
minimum-initial-energy-to-finish-tasks | Java | Greedy approach with sorting O(nlogn) | java-greedy-approach-with-sorting-onlogn-l0uh | \nclass Solution {\n public int minimumEffort(int[][] tasks) {\n Arrays.sort(tasks, (t1, t2) -> (t2[1]-t2[0]) - (t1[1]-t1[0]));\n int initial = | levimor | NORMAL | 2020-12-05T09:27:57.980489+00:00 | 2022-06-17T10:35:40.202901+00:00 | 354 | false | ```\nclass Solution {\n public int minimumEffort(int[][] tasks) {\n Arrays.sort(tasks, (t1, t2) -> (t2[1]-t2[0]) - (t1[1]-t1[0]));\n int initial = 0, current = 0;\n for (int[] task : tasks) {\n if (current < task[1]) {\n initial += task[1] - current;\n cu... | 2 | 0 | ['Greedy', 'Sorting', 'Java'] | 0 |
minimum-initial-energy-to-finish-tasks | C++ greedy O(n) Runtime with O(n) space and easy to understand with explanation | c-greedy-on-runtime-with-on-space-and-ea-ig6l | Intution here is we need to work on the tasks whose difference of enery to begin and energy to complete in decreasing order which allows us to spend enery more | sanjayreddy | NORMAL | 2020-11-22T17:42:15.932740+00:00 | 2020-11-22T17:42:15.932772+00:00 | 198 | false | * **Intution** here is we need to work on the tasks whose difference of enery to begin and energy to complete in decreasing order which allows us to spend enery more efficiently.\n* **Algorithm:**\n\t1. Lets first calculate total energy required to finish all the tasks ie. tasks[0][0]+tasks[1][0]+...+tasks[n-1][0]\n\t2... | 2 | 0 | ['Greedy', 'C'] | 0 |
minimum-initial-energy-to-finish-tasks | Simple Python solution using sort | simple-python-solution-using-sort-by-gra-eqwz | \ndef minimumEffort(self, tasks: List[List[int]]) -> int:\n tasks.sort(key=lambda a:a[1]-a[0],reverse=True)\n res,curr=0,0\n for i,j in tas | GrandWarden | NORMAL | 2020-11-22T15:54:45.237441+00:00 | 2020-11-22T15:56:54.027853+00:00 | 79 | false | ```\ndef minimumEffort(self, tasks: List[List[int]]) -> int:\n tasks.sort(key=lambda a:a[1]-a[0],reverse=True)\n res,curr=0,0\n for i,j in tasks:\n if curr<j:\n res+=j-curr\n curr=j\n curr-=i\n return res\n``` | 2 | 0 | [] | 0 |
minimum-initial-energy-to-finish-tasks | Simplest proof of greedy correctness | simplest-proof-of-greedy-correctness-by-z9m4r | Suppose an ordering of the tasks can be completed with some initial energy; assume the ordering has consecutive tasks [a1, m1] and [a2, m2] where m1 - a1 < m2 - | subfallen | NORMAL | 2020-11-22T06:29:06.398679+00:00 | 2020-11-22T06:30:18.774071+00:00 | 77 | false | Suppose an ordering of the tasks can be completed with some initial energy; assume the ordering has consecutive tasks `[a1, m1]` and `[a2, m2]` where `m1 - a1 < m2 - a2`.\n\nWe claim we can reverse the order of these two tasks, and the result will still be completable with the same initial energy. Indeed, suppose energ... | 2 | 0 | [] | 0 |
minimum-initial-energy-to-finish-tasks | python3 with explaination | python3-with-explaination-by-bakerston-ez16 | Sorted tasks by the different between minimum required energy and energy cost, which is x[1]-x[0].\nKeep merging two tasks into a single task, until we only hav | Bakerston | NORMAL | 2020-11-22T04:14:19.232774+00:00 | 2020-11-22T04:14:54.183444+00:00 | 123 | false | Sorted tasks by the different between minimum required energy and energy cost, which is *x[1]-x[0]*.\nKeep merging two tasks into a single task, until we only have one task.\n\nThe cost of the combined task equals to the sum of the energy cost of two tasks.\nFor minimum required energy, lets assume we start with task1 ... | 2 | 0 | [] | 0 |
minimum-initial-energy-to-finish-tasks | C++ greedy solution | c-greedy-solution-by-meliky-eo45 | \nstatic bool compare(vector<int>& left, vector<int>& right){\n if(left[1] - left[0] == right[1] - right[0])\n {\n return left[0] > rig | meliky | NORMAL | 2020-11-22T04:12:16.817831+00:00 | 2020-11-22T04:12:16.817872+00:00 | 91 | false | ```\nstatic bool compare(vector<int>& left, vector<int>& right){\n if(left[1] - left[0] == right[1] - right[0])\n {\n return left[0] > right[0]; \n }\n return left[1] - left[0] < right[1] -right[0];\n }\n int minimumEffort(vector<vector<int>>& tasks) {\n sort(tasks.be... | 2 | 0 | [] | 0 |
minimum-initial-energy-to-finish-tasks | Python Greedy 8 Lines | python-greedy-8-lines-by-sailormoons-359h | \ndef minimumEffort(self, tasks):\n\tsort = sorted(tasks, key = lambda x : x[1] - x[0])[::-1]\n\tres = 0; curr = 0\n\tfor i, n in enumerate(sort):\n\t\tif curr | SailorMoons | NORMAL | 2020-11-22T04:04:30.097104+00:00 | 2020-11-22T04:05:05.975716+00:00 | 128 | false | ```\ndef minimumEffort(self, tasks):\n\tsort = sorted(tasks, key = lambda x : x[1] - x[0])[::-1]\n\tres = 0; curr = 0\n\tfor i, n in enumerate(sort):\n\t\tif curr < n[1]:\n\t\t\tres += n[1] - curr\n\t\t\tcurr = n[1]\n\t\tcurr -= n[0]\n\treturn res\n``` | 2 | 0 | [] | 1 |
minimum-initial-energy-to-finish-tasks | Clean Java Code O(n log n) | clean-java-code-on-log-n-by-navid-y13h | \n\n public int minimumEffort(int[][] tasks) {\n List energyList = getEnergyList(tasks);\n return getMinimumRequiredEnergy(energyList);\n }\ | navid | NORMAL | 2020-11-22T04:02:28.950310+00:00 | 2020-11-22T05:55:15.489679+00:00 | 188 | false | \n\n public int minimumEffort(int[][] tasks) {\n List<Energy> energyList = getEnergyList(tasks);\n return getMinimumRequiredEnergy(energyList);\n }\n\n private int getMinimumRequiredEnergy(List<Energy> energyList) {\n int requiredEnergy = 0;\n int remainingEnergy = 0;\n for (... | 2 | 0 | [] | 0 |
minimum-initial-energy-to-finish-tasks | Greedy Task Energy Minimization | greedy-task-energy-minimization-by-imund-2bql | IntuitionTo minimize the initial energy needed to complete all tasks, we should order the tasks in a way that avoids having to "top up" energy unnecessarily. Ta | imundertheree | NORMAL | 2025-04-06T20:06:36.558884+00:00 | 2025-04-06T20:06:36.558884+00:00 | 9 | false | # Intuition
To minimize the initial energy needed to complete all tasks, we should order the tasks in a way that avoids having to "top up" energy unnecessarily. Tasks that have a large gap between the required minimum energy and actual effort are more restrictive and should be prioritized earlier.
# Approach
1. Sort t... | 1 | 0 | ['Python3'] | 0 |
minimum-initial-energy-to-finish-tasks | Beginner Friendly || Beats 100% Runtime in CPP || Easiest CPP Solution | beginner-friendly-beats-100-runtime-in-c-j8ha | IntuitionTukkaApproachBy Aman VishwakarmaComplexity
Time complexity: O(n∗logn)
Space complexity:O(1)
Code | Aman_Vi | NORMAL | 2025-04-02T18:55:55.820630+00:00 | 2025-04-02T18:55:55.820630+00:00 | 12 | false | # Intuition
Tukka
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
By Aman Vishwakarma
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity: $$O(n*logn)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:$$O(1)$$
<!-- Add your sp... | 1 | 0 | ['Array', 'Sorting', 'C++'] | 0 |
minimum-initial-energy-to-finish-tasks | Very good problem | very-good-problem-by-simolekc-ym0v | Code | simolekc | NORMAL | 2025-02-07T12:17:29.036502+00:00 | 2025-02-07T12:17:29.036502+00:00 | 7 | false |
# Code
```javascript []
/**
* @param {number[][]} tasks
* @return {number}
*/
var minimumEffort = function (tasks) {
let n = tasks.length;
tasks.sort((a, b) => a[0] - a[1] + b[1] - b[0]);
let needEnergy = -Infinity;
let used = 0;
let cost, need;
for (let i = 0; i < n; i++) {
[cost... | 1 | 0 | ['JavaScript'] | 0 |
minimum-initial-energy-to-finish-tasks | Simple math | Easy to Understand | Python | simple-math-easy-to-understand-python-by-2z4q | IntuitionBinary search is the first intutionApproachlet us take the general example of two tasks
task1 = [actual1, minimum1] and task2 = [actual2, minimum2]let | sheshankkumarsingh28 | NORMAL | 2025-01-08T11:29:38.663168+00:00 | 2025-01-08T11:29:38.663168+00:00 | 45 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Binary search is the first intution
# Approach
<!-- Describe your approach to solving the problem. -->
let us take the general example of two tasks
task1 = [actual1, minimum1] and task2 = [actual2, minimum2]
let us first consider the case... | 1 | 0 | ['Python3'] | 0 |
minimum-initial-energy-to-finish-tasks | EASY AND SIMPLE JAVA SOLUTION (WITH EXPLAINATION). | easy-and-simple-java-solution-with-expla-9c09 | 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 | ManasSingh7 | NORMAL | 2024-03-20T06:50:29.895596+00:00 | 2024-03-20T06:50:29.895672+00:00 | 44 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['Java'] | 0 |
minimum-initial-energy-to-finish-tasks | Most Easy cpp solution(Beats 100%) | most-easy-cpp-solutionbeats-100-by-sanya-bjkf | 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 | sanyam46 | NORMAL | 2023-08-02T14:27:34.042055+00:00 | 2023-08-02T14:27:34.042080+00:00 | 137 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:O(NLogN)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O... | 1 | 0 | ['C++'] | 0 |
minimum-initial-energy-to-finish-tasks | C++✅✅ | Custom Sort | Easy Solution | Clean Code | | c-custom-sort-easy-solution-clean-code-b-6ueh | \n\n# Code\n\n\nclass Solution {\npublic:\n\nstatic bool cmp(vector<int>&v1, vector<int>&v2)\n{\n return v1[1] - v1[0] > v2[1] - v2[0];\n}\n\n int min | mr_kamran | NORMAL | 2022-11-28T04:15:07.067638+00:00 | 2022-11-28T04:15:39.921577+00:00 | 169 | false | \n\n# Code\n```\n\nclass Solution {\npublic:\n\nstatic bool cmp(vector<int>&v1, vector<int>&v2)\n{\n return v1[1] - v1[0] > v2[1] - v2[0];\n}\n\n int minimumEffort(vector<vector<int>>& tasks) {\n\n \n sort(tasks.begin(),tasks.end(),cmp);\n\n int ans = tasks[0][1];\n int temp = ans - t... | 1 | 0 | ['C++'] | 0 |
minimum-initial-energy-to-finish-tasks | C++ || Intuitions Explained || Binary Search || Thanks to chipbk10 | c-intuitions-explained-binary-search-tha-0bsx | \n#define ll long long\n\nclass Solution {\npublic:\n // Basically this question is based amount of profit u can get \n \n // so u want to invest on th | KR_SK_01_In | NORMAL | 2022-08-02T15:19:36.968885+00:00 | 2022-08-02T15:20:20.105062+00:00 | 143 | false | ```\n#define ll long long\n\nclass Solution {\npublic:\n // Basically this question is based amount of profit u can get \n \n // so u want to invest on those tasks where u will get more profits \n \n // so sorting must be done on the basis of differnces \n \n // take firstly those pairs which has m... | 1 | 0 | ['Greedy', 'C', 'Sorting', 'Binary Tree', 'C++'] | 0 |
minimum-initial-energy-to-finish-tasks | Java Solution | Binary search | Sorting | java-solution-binary-search-sorting-by-m-fgfm | Sort the array according to diffference between minimun energy and actual energy(In descending order)\n2. Calculate the sum of actual energy and sum of minimum | mihir05 | NORMAL | 2022-08-02T06:17:50.419384+00:00 | 2022-08-02T06:17:50.419430+00:00 | 202 | false | 1. Sort the array according to diffference between minimun energy and actual energy(In descending order)\n2. Calculate the sum of actual energy and sum of minimum energy i.e sum of tasks[i][0] and tasks[i][1]\n3. we know that our answer lies between these two sum, we can use binary search to find the answer, if mid is ... | 1 | 0 | ['Sorting', 'Binary Tree', 'Java'] | 0 |
minimum-initial-energy-to-finish-tasks | Java || Greedy || O(N logN ) time || O(1) space | java-greedy-on-logn-time-o1-space-by-nam-2yaz | sort it by difference between minimum energy and needed energy\n```\nclass Solution {\n public int minimumEffort(int[][] tasks) {\n Arrays.sort(tasks, | namansachan7 | NORMAL | 2022-03-12T08:10:05.079843+00:00 | 2022-03-12T08:10:05.079893+00:00 | 190 | false | sort it by difference between minimum energy and needed energy\n```\nclass Solution {\n public int minimumEffort(int[][] tasks) {\n Arrays.sort(tasks,(a,b)->a[1]-a[0]-b[1]+b[0]);\n int prev=0;\n for (int[] item:tasks){\n prev=Math.max(prev+item[0],item[1]);\n }\n return ... | 1 | 0 | ['Greedy', 'Sorting', 'Java'] | 0 |
minimum-initial-energy-to-finish-tasks | Simple 4-line solution, faster than 80% | simple-4-line-solution-faster-than-80-by-bxui | Key Insight\n\nWanting the smallest possible starting value is the same as wanting the smallest possible ending value.\n\n# Algorithm\nTherefore sort the tasks | darrelfrancis | NORMAL | 2021-11-19T08:05:02.894870+00:00 | 2021-11-19T08:06:12.219811+00:00 | 175 | false | # Key Insight\n\nWanting the smallest possible _starting_ value is the same as wanting the smallest possible _ending_ value.\n\n# Algorithm\nTherefore sort the tasks in order of what is the smallest possible energy value that can exist after the task runs. This is _minimum MINUS actual_.\n\nThen loop through the sorted... | 1 | 0 | ['Python'] | 0 |
minimum-initial-energy-to-finish-tasks | Python, sort then dp | python-sort-then-dp-by-404akhan-mj35 | Sort by minimum_i - actual_i, then do dp.\n\nYou can show that if you have minimum_i - actual_i not in sorted order, you can swap them and using bubble sort eve | 404akhan | NORMAL | 2021-11-17T14:08:52.818547+00:00 | 2021-11-17T14:08:52.818587+00:00 | 120 | false | Sort by `minimum_i - actual_i`, then do dp.\n\nYou can show that if you have `minimum_i - actual_i` not in sorted order, you can swap them and using bubble sort eventually sort them and still have valid solution (with same initial amount of energy). Just write down inequalities.\n\nNow after sorting we get easy dp, whe... | 1 | 0 | [] | 0 |
minimum-initial-energy-to-finish-tasks | C++ | c-by-priyanka1230-u1ck | \n\npublic:\n static bool cmp(vector&v1,vector&v2)\n {\n return (v1[0]-v1[1])>(v2[0]-v2[1]);\n }\n int minimumEffort(vector>& tasks) {\n | priyanka1230 | NORMAL | 2021-08-09T17:13:00.938174+00:00 | 2021-08-09T17:13:00.938219+00:00 | 75 | false | ```\n\n```public:\n static bool cmp(vector<int>&v1,vector<int>&v2)\n {\n return (v1[0]-v1[1])>(v2[0]-v2[1]);\n }\n int minimumEffort(vector<vector<int>>& tasks) {\n sort(tasks.begin(),tasks.end(),cmp);\n int i,sum=0;\n for(i=0;i<tasks.size();i++)\n {\n sum=max(t... | 1 | 0 | [] | 0 |
minimum-initial-energy-to-finish-tasks | Python3 - greedy, with intuition, algorithm, and proof | python3-greedy-with-intuition-algorithm-i3gzs | Intuition\nFor the last task, we will want to minimize the waste of energy, so we take the task which has the smallest (minimum - actual). If we waste more ener | yunqu | NORMAL | 2021-05-27T02:01:12.772361+00:00 | 2021-05-27T02:35:00.878470+00:00 | 108 | false | **Intuition**\nFor the last task, we will want to minimize the waste of energy, so we take the task which has the smallest (minimum - actual). If we waste more energy, we know it could be done, but it is just not optimal.\n\n**Algorithm**\nContinuing this thinking for all the remaining tasks, we know at each step, we m... | 1 | 0 | [] | 0 |
minimum-initial-energy-to-finish-tasks | C++ sort by difference and explanation in details | c-sort-by-difference-and-explanation-in-oinjp | This is how I came up with the idea that we need to sort the vector by difference. Please let me know if I am not clear enough to you.\n\n1) Supposed we have a | brandonyxf | NORMAL | 2021-05-14T04:20:18.306823+00:00 | 2021-05-14T04:20:18.306858+00:00 | 124 | false | This is how I came up with the idea that we need to sort the vector by difference. Please let me know if I am not clear enough to you.\n\n1) Supposed we have a huge amount of energy which is enough to finish all tasks. There must be some energy left, and we defined it as \'res\'. If we want to finish all the tasks wi... | 1 | 0 | [] | 0 |
minimum-initial-energy-to-finish-tasks | Proof with induction | proof-with-induction-by-infinitetape-uo7t | Assertion: if x as initial energy can finish all tasks in some order, then it must be sufficient to finish all tasks in descending order by (minium \u2013 actua | infinitetape | NORMAL | 2021-05-14T01:43:00.493296+00:00 | 2021-05-14T01:43:00.493344+00:00 | 89 | false | Assertion: if x as initial energy can finish all tasks in some order, then it must be sufficient to finish all tasks in descending order by (minium \u2013 actual).\n\nProof:\nIf there is 1 task, the assertion is obviously true.\n\nIf there are 2 tasks, let\u2019s say we have: [a, a + c1] and [b, b + c2], and c1 >= c2.\... | 1 | 0 | [] | 0 |
minimum-initial-energy-to-finish-tasks | c++ solution of the problem | c-solution-of-the-problem-by-sw2000-ra5u | can anyone explain why i am getting TLE with this code?\n \n\n static bool cmp(vector<int>v1,vector<int>v2){\n \n return ((v1[1]-v1[0])>(v2[1]-v2[ | sw2000 | NORMAL | 2021-05-02T04:06:35.985899+00:00 | 2021-05-28T09:28:12.394898+00:00 | 167 | false | can anyone explain why i am getting TLE with this code?\n \n```\n static bool cmp(vector<int>v1,vector<int>v2){\n \n return ((v1[1]-v1[0])>(v2[1]-v2[0]));\n }\n int minimumEffort(vector<vector<int>>& tasks) {\n \n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.... | 1 | 0 | [] | 2 |
minimum-initial-energy-to-finish-tasks | [Java] Straightforward from the question | java-straightforward-from-the-question-b-4pxc | First, we can think about stratgy to have minimum energy to do all the tasks.\n\nThe first idea come to mind is working on a task with highest minimum value. Ho | heemin32 | NORMAL | 2021-03-20T05:22:12.152900+00:00 | 2021-03-20T05:22:12.152932+00:00 | 126 | false | First, we can think about stratgy to have minimum energy to do all the tasks.\n\nThe first idea come to mind is working on a task with highest minimum value. However, we can easily find the case where this does not work.\nFor example, with [1, 10] and [1, 2], we should work on [1, 2] first to finish them with 11 energy... | 1 | 0 | [] | 1 |
minimum-initial-energy-to-finish-tasks | Interval scheduling intuition | interval-scheduling-intuition-by-louisqi-d0kp | The problem could be converted into the classic greedy interval scheduling problem. Although this might not be the most optimal solution in terms of runtime, I | louisqin | NORMAL | 2021-03-01T06:53:31.708437+00:00 | 2021-03-01T06:53:31.708475+00:00 | 599 | false | The problem could be converted into the classic greedy interval scheduling problem. Although this might not be the most optimal solution in terms of runtime, I find it very helpful to gain an intuitive understanding of the problem.\n\nHere, we map the concepts in the problem into those in interval scheduling:\n* minimu... | 1 | 0 | [] | 0 |
minimum-initial-energy-to-finish-tasks | C# one line with linq | c-one-line-with-linq-by-user1696y-u1oy | \n public int MinimumEffort(int[][] tasks) {\n return tasks.OrderBy(x => x[1] - x[0]).Aggregate(0, (result, x) => Math.Max(result + x[0], x[1])); | user1696y | NORMAL | 2021-02-14T16:27:21.625007+00:00 | 2021-02-14T16:27:21.625040+00:00 | 67 | false | ```\n public int MinimumEffort(int[][] tasks) {\n return tasks.OrderBy(x => x[1] - x[0]).Aggregate(0, (result, x) => Math.Max(result + x[0], x[1])); \n }\n``` | 1 | 0 | [] | 0 |
minimum-initial-energy-to-finish-tasks | JAVA 90% FAST SIMPLE SOLUTION WITH EXPLANATION WITH TIME AND SPACE | java-90-fast-simple-solution-with-explan-s91z | EXPLANATION:\n required will be minimum if first we choose:\n 1.task with minimum consumption.\n 2.task with maximum initial requirement.\nBUT, both ar | shivam_gupta_ | NORMAL | 2021-02-01T09:01:13.984244+00:00 | 2021-02-01T09:01:13.984281+00:00 | 119 | false | EXPLANATION:\n required will be minimum if first we choose:\n 1.task with minimum consumption.\n 2.task with maximum initial requirement.\nBUT, both are opposite task so we will sort task based on difference b/w initial requirement and consumption. if its same than based on maximum requirement if its also same... | 1 | 0 | [] | 0 |
minimum-initial-energy-to-finish-tasks | [Python] Binary search solution | python-binary-search-solution-by-modusv-wqu4 | Greedily test an initial energy value and use binary search to span over all the possible initial values.\n\n\nclass Solution:\n def minimumEffort(self, task | modusv | NORMAL | 2020-12-22T14:43:38.622968+00:00 | 2020-12-22T14:44:51.944423+00:00 | 122 | false | Greedily test an initial energy value and use binary search to span over all the possible initial values.\n\n```\nclass Solution:\n def minimumEffort(self, tasks: List[List[int]]) -> int:\n \n def enough(en):\n for actual, minim in tasks:\n if en >= minim:\n ... | 1 | 0 | [] | 0 |
minimum-initial-energy-to-finish-tasks | Java sort by (minimum-actual) | java-sort-by-minimum-actual-by-mayankban-zax6 | ```\nclass Solution {\n public int minimumEffort(int[][] tasks) {\n Arrays.sort(tasks,(a,b)->(b[1]-b[0])-(a[1]-a[0]));\n int energy=0;\n | mayankbansal | NORMAL | 2020-11-30T06:56:16.449702+00:00 | 2020-11-30T06:56:16.449743+00:00 | 97 | false | ```\nclass Solution {\n public int minimumEffort(int[][] tasks) {\n Arrays.sort(tasks,(a,b)->(b[1]-b[0])-(a[1]-a[0]));\n int energy=0;\n int ans=0;\n for(int i=0;i<tasks.length;i++){\n if(energy<tasks[i][1]){\n int req=tasks[i][1]-energy;\n energy+... | 1 | 0 | [] | 0 |
minimum-initial-energy-to-finish-tasks | [C#] O(N) Two Lines | c-on-two-lines-by-a-f-v-ngja | Algorithm\nStep 1) Sum all the actual costs together and add the smallest difference between minimum and actual (this corresponds to summing all actual costs ex | a-f-v | NORMAL | 2020-11-23T00:41:31.266068+00:00 | 2020-11-23T00:43:35.777912+00:00 | 69 | false | # Algorithm\nStep 1) Sum all the actual costs together and add the smallest difference between minimum and actual (this corresponds to summing all actual costs excluding your last choice which needs to use minimum)\nStep 2) Make sure it is not greater than largest minimum\n# Code\n```csharp\npublic class Solution {\npu... | 1 | 0 | ['C#'] | 1 |
minimum-initial-energy-to-finish-tasks | Easy JAVA Solution | O(n logn) | Sorting | easy-java-solution-on-logn-sorting-by-mi-cllk | Easy to understand Java Solution\nSorting on the basis of MAXIMUM Difference between the Minimum And Actual Energy Requirements\n\n\nclass Solution {\n publi | mihir_sood | NORMAL | 2020-11-22T04:32:10.343794+00:00 | 2020-11-22T04:32:10.343839+00:00 | 138 | false | Easy to understand Java Solution\nSorting on the basis of MAXIMUM Difference between the Minimum And Actual Energy Requirements\n\n```\nclass Solution {\n public int minimumEffort(int[][] tasks) {\n int tot=0; // total effort required\n for(int[] t:tasks){\n tot+=t[0];\n }\n in... | 1 | 1 | ['Array', 'Greedy', 'Sorting', 'Java'] | 0 |
minimum-initial-energy-to-finish-tasks | [c++] Binary Search TLE | c-binary-search-tle-by-askvij-weit | I see lots of solution passed using binary serach. I got TLE using binary serach wondering why ?\n\n\nclass Solution {\npublic:\n int minimumEffort(vector< | askvij | NORMAL | 2020-11-22T04:29:55.919522+00:00 | 2020-11-22T06:43:05.455725+00:00 | 346 | false | I see lots of solution passed using binary serach. I got TLE using binary serach wondering why ?\n\n```\nclass Solution {\npublic:\n int minimumEffort(vector<vector<int>>& tasks) {\n long long lo = 0, hi = 0;\n for (auto task : tasks) lo += task[0], hi += task[1];\n sort(tasks.begin(), tasks.e... | 1 | 0 | ['Binary Tree'] | 3 |
minimum-initial-energy-to-finish-tasks | [Help] Why Binary Search gives TLE ? | help-why-binary-search-gives-tle-by-vrko-36dn | I have code it using binary search.\n\ncomplexity can be O(nlog(1e9)).\nstill it gives TLE. while other users having same approach got it accepted.\nPlease help | vrkorat211 | NORMAL | 2020-11-22T04:28:31.014909+00:00 | 2020-11-22T04:28:31.014939+00:00 | 240 | false | I have code it using binary search.\n\ncomplexity can be O(nlog(1e9)).\nstill it gives TLE. while other users having same approach got it accepted.\nPlease help where i am missing something?\nThanks in advance.\n```\nclass Solution {\npublic:\n int minimumEffort(vector<vector<int>>& a) {\n sort(a.begin(),a.en... | 1 | 0 | ['Binary Tree'] | 1 |
minimum-initial-energy-to-finish-tasks | [C++] Can anyone help me explain this ? Please! | c-can-anyone-help-me-explain-this-please-0obb | \tclass Solution {\n\tpublic:\n\t\tint minimumEffort(vector>& tasks) {\n\t\t\tauto comp = {\n\t\t\t\tint diff1 = abs(a[1] - a[0]);\n\t\t\t\tint diff2 = abs(b[1 | jasperzhou | NORMAL | 2020-11-22T04:15:48.980191+00:00 | 2020-11-22T04:15:48.980230+00:00 | 161 | false | \tclass Solution {\n\tpublic:\n\t\tint minimumEffort(vector<vector<int>>& tasks) {\n\t\t\tauto comp = [](vector<int>& a, vector<int>& b) {\n\t\t\t\tint diff1 = abs(a[1] - a[0]);\n\t\t\t\tint diff2 = abs(b[1] - b[0]);\n\t\t\t\treturn diff1 >= diff2;\n\t\t\t};//when I use this to sort, I got an error, but when I deleted ... | 1 | 0 | ['Binary Tree'] | 1 |
minimum-initial-energy-to-finish-tasks | [Java] DFS Permutation TLE | java-dfs-permutation-tle-by-sheepmeow-9rdm | This solution only passes 10/41 testcases. It\'s apparently very slow because it tries to search through permutations of doing tasks in different orders, so tha | sheepmeow | NORMAL | 2020-11-22T04:07:39.552975+00:00 | 2020-11-22T04:07:39.553005+00:00 | 71 | false | This solution only passes 10/41 testcases. It\'s apparently very slow because it tries to search through permutations of doing tasks in different orders, so that gives a runtime of O(n!) where n is number of tasks...\nComments/thoughts on improvement are welcome!\n```java\nclass Solution {\n // dfs, do task i, find ... | 1 | 1 | [] | 0 |
minimum-initial-energy-to-finish-tasks | I love python. It makes everything so easy to write | i-love-python-it-makes-everything-so-eas-mp2r | \n0class Solution:\n def minimumEffort(self, tasks: List[List[int]]) -> int:\n ret = 0\n dict1 = {}\n for i in range(0, len(tasks)):\n | waluigi120 | NORMAL | 2020-11-22T04:05:32.629899+00:00 | 2020-11-22T04:05:32.629942+00:00 | 74 | false | ```\n0class Solution:\n def minimumEffort(self, tasks: List[List[int]]) -> int:\n ret = 0\n dict1 = {}\n for i in range(0, len(tasks)):\n dict1[i] = tasks[i][1]-tasks[i][0]\n for k,v in sorted(dict1.items(), key=lambda item: item[1]):\n if tasks[k][0] + ret < tasks[k... | 1 | 0 | [] | 0 |
minimum-initial-energy-to-finish-tasks | Java Code with custom sort and comment | java-code-with-custom-sort-and-comment-b-3a9x | Sort the array with largest minumum-actual for each task, the top priority is the one with largest difference\nThen build up the minimum requirements by iterati | htttth | NORMAL | 2020-11-22T04:04:02.691832+00:00 | 2020-11-22T04:04:02.691874+00:00 | 81 | false | Sort the array with largest minumum-actual for each task, the top priority is the one with largest difference\nThen build up the minimum requirements by iterating the sorted array and add energy if the remaining is not enough for the next minimum\n\n public int minimumEffort(int[][] tasks) {\n \n // So... | 1 | 0 | [] | 0 |
minimum-initial-energy-to-finish-tasks | Python Binary Search | python-binary-search-by-an8888ha-ukmx | Pick those task first which are trying hard to show off.\nMeans abs(min-actual)\n\n\nclass Solution:\n def isPossible(self, tasks, energy):\n for task | an8888ha | NORMAL | 2020-11-22T04:01:16.263724+00:00 | 2020-11-22T04:01:16.263767+00:00 | 143 | false | Pick those task first which are trying hard to show off.\nMeans abs(min-actual)\n\n```\nclass Solution:\n def isPossible(self, tasks, energy):\n for task in tasks:\n required,show = task\n if energy < show or energy < required:\n return False\n energy -= require... | 1 | 0 | [] | 0 |
minimum-initial-energy-to-finish-tasks | Sorting | Easy Solution | 29ms | Beats 93% | sorting-easy-solution-29ms-beats-93-by-a-5pf5 | Complexity
Time complexity: O(n)
Space complexity: O(1)
Code | arjav2768 | NORMAL | 2025-03-28T15:21:38.730599+00:00 | 2025-03-28T15:21:38.730599+00:00 | 4 | false | # Complexity
- Time complexity: O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: O(1)
# Code
```cpp []
class Solution {
public:
int minimumEffort(vector<vector<int>>& tasks) {
sort(tasks.begin(),tasks.end(),[](vector<int> &a, vector<int> &b){
return a[1]-a[0] > b[... | 0 | 0 | ['Sorting', 'C++'] | 0 |
minimum-initial-energy-to-finish-tasks | EASY JAVA | easy-java-by-navalbihani15-85ms | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | navalbihani15 | NORMAL | 2025-03-27T10:54:43.460707+00:00 | 2025-03-27T10:54:43.460707+00:00 | 0 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['Java'] | 0 |
minimum-initial-energy-to-finish-tasks | EASY JAVA | easy-java-by-navalbihani15-z1se | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | navalbihani15 | NORMAL | 2025-03-27T10:54:41.681129+00:00 | 2025-03-27T10:54:41.681129+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['Java'] | 0 |
minimum-initial-energy-to-finish-tasks | [easy intuition] [step-by-step explanation] sorting solution | easy-intuition-step-by-step-explanation-wx9v9 | Intuitionsome terminology : process a task = finish a task = finish an elementNow, let think in the direction if we are not given with the term minimumi.
Then, | somil_jain_120 | NORMAL | 2025-02-01T04:28:38.005863+00:00 | 2025-02-01T04:28:38.005863+00:00 | 3 | false | # Intuition
some terminology : process a task = finish a task = finish an element
Now, let think in the direction if we are not given with the term $$\text{minimum}_i$$.
Then, our answer would always be sum of all the $$\operatorname{actual}_i$$.
So, lets start with this answer only, that is, initial energy = sum of... | 0 | 0 | ['Greedy', 'Sorting', 'C++'] | 0 |
minimum-initial-energy-to-finish-tasks | CPP Sorting + Binary Search | cpp-sorting-binary-search-by-zaid_shaikh-6syl | Complexity
Time complexity:
O(NlogM)
Space complexity:
O(1)
Code | Zaid_Shaikh001 | NORMAL | 2025-01-25T19:51:04.723588+00:00 | 2025-01-25T19:51:04.723588+00:00 | 5 | false |
# Complexity
- Time complexity:
O(NlogM)
- Space complexity:
O(1)
# Code
```cpp []
class Solution {
public:
bool canComplete(long long currentEnergy, vector<vector<int>>& tasks) {
for (auto t : tasks) {
if (currentEnergy >= t[1]) {
currentEnergy -= t[0];
} else {
... | 0 | 0 | ['Array', 'Greedy', 'Sorting', 'C++'] | 0 |
minimum-initial-energy-to-finish-tasks | 1665. Minimum Initial Energy to Finish Tasks | 1665-minimum-initial-energy-to-finish-ta-kgyv | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | G8xd0QPqTy | NORMAL | 2025-01-14T14:41:12.057638+00:00 | 2025-01-14T14:41:12.057638+00:00 | 10 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['Python3'] | 0 |
minimum-initial-energy-to-finish-tasks | DP greedy sort | dp-greedy-sort-by-quinnhindmarsh-52h1 | IntuitionWe want do to the tasks with the least difference between the start and actual cost last.Approach
Sort the array by minimum difference between start an | quinnhindmarsh | NORMAL | 2024-12-24T03:29:34.026424+00:00 | 2024-12-24T03:29:34.026424+00:00 | 7 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We want do to the tasks with the least difference between the start and actual cost last.
# Approach
<!-- Describe your approach to solving the problem. -->
1. Sort the array by minimum difference between start and actual cost.
2. Determi... | 0 | 0 | ['Dynamic Programming', 'Greedy', 'Sorting', 'Prefix Sum', 'Python3'] | 0 |
minimum-initial-energy-to-finish-tasks | mathematical proof of greedy | mathematical-proof-of-greedy-by-___arash-keic | Mathematical Proof of greedy
lets assume I have budget=budget
doing (a,b) first and then (c,d) is better or doing (c,d) first and then (a,b). Assuming: d-c> | ___Arash___ | NORMAL | 2024-12-24T00:24:58.550505+00:00 | 2024-12-24T00:24:58.550505+00:00 | 3 | false | # Mathematical Proof of greedy
1. lets assume I have budget=budget
2. doing (a,b) first and then (c,d) is better or doing (c,d) first and then (a,b). Assuming: d-c>=b-a
3. if we prove that doing (c,d) first and then (a,b) is better, we actually proved greedy approach and why we sort and why we start from the one havi... | 0 | 0 | ['Python'] | 0 |
minimum-initial-energy-to-finish-tasks | Minimum Initial Energy to Finish Tasks Runtime 100% and Memory 90 % | minimum-initial-energy-to-finish-tasks-r-czk5 | Intuition\nThe key insight is that we want to minimize the initial energy required to complete all tasks. Tasks with a high minimum requirement but low actual e | FujMYV1KQS | NORMAL | 2024-12-09T03:28:40.885404+00:00 | 2024-12-09T03:28:40.885429+00:00 | 2 | false | # Intuition\nThe key insight is that we want to minimize the initial energy required to complete all tasks. Tasks with a high minimum requirement but low actual energy consumption should be done first, as they have the biggest impact on our initial energy needs.\n\n# Approach\n1. Sort the tasks based on the difference ... | 0 | 0 | ['C#'] | 0 |
minimum-initial-energy-to-finish-tasks | Greedy after Sorting based on the difference !! | greedy-after-sorting-based-on-the-differ-6xff | Approach: \n- We just need to sort the tasks vector based on the difference between the actual & minimum energy required in descending order.\n- Then we can tra | Axnjr | NORMAL | 2024-10-29T11:58:47.229592+00:00 | 2024-10-29T11:58:47.229634+00:00 | 5 | false | # Approach: \n- We just need to sort the `tasks` vector based on the difference between the actual & minimum energy required in descending order.\n- Then we can traverse the sorted array with `startEnergy` & `remEnergy` variables set to `0`.\n- We will keep adding the `diff` required to keep doing tasks. `GREEDY \uD83E... | 0 | 0 | ['Greedy', 'Sorting', 'C++'] | 0 |
minimum-initial-energy-to-finish-tasks | Custom Sort Greedily | custom-sort-greedily-by-theabbie-o0db | \nfrom functools import cmp_to_key\n\nclass Solution:\n def minimumEffort(self, tasks: List[List[int]]) -> int:\n def cmp(a, b):\n if max(a | theabbie | NORMAL | 2024-10-22T18:53:03.027186+00:00 | 2024-10-22T18:53:03.027209+00:00 | 2 | false | ```\nfrom functools import cmp_to_key\n\nclass Solution:\n def minimumEffort(self, tasks: List[List[int]]) -> int:\n def cmp(a, b):\n if max(a[1], a[0] + max(b[0], b[1])) > max(b[1], b[0] + max(a[0], a[1])):\n return 1\n return -1\n tasks.sort(key = cmp_to_key(cmp))... | 0 | 0 | ['Python'] | 0 |
minimum-initial-energy-to-finish-tasks | Minimum Initial Energy to Finish Tasks | minimum-initial-energy-to-finish-tasks-b-8eqx | Approach\n Describe your approach to solving the problem. \nSort the Tasks by "Difference":\nWe should prioritize tasks that have a larger difference between mi | Ansh1707 | NORMAL | 2024-10-11T04:53:38.741556+00:00 | 2024-10-11T04:53:38.741592+00:00 | 2 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nSort the Tasks by "Difference":\nWe should prioritize tasks that have a larger difference between minimumi and actuali. This way, we maximize the leftover energy by starting with tasks that are "expensive" in terms of their starting requirement but "c... | 0 | 0 | ['Python'] | 0 |
minimum-initial-energy-to-finish-tasks | 1665. Minimum Initial Energy to Finish Tasks.cpp | 1665-minimum-initial-energy-to-finish-ta-xo8n | Code\n\nclass Solution {\npublic: \n static bool cmp(const pair<int,pair<int,int>>&a,const pair<int,pair<int,int>>&b)\n {\n if(a.first==b.first) | 202021ganesh | NORMAL | 2024-10-08T07:26:46.784948+00:00 | 2024-10-08T07:26:46.784972+00:00 | 2 | false | **Code**\n```\nclass Solution {\npublic: \n static bool cmp(const pair<int,pair<int,int>>&a,const pair<int,pair<int,int>>&b)\n {\n if(a.first==b.first)\n {\n return a.second.second>b.second.second;\n }\n else\n return a.first>b.first; \n } \n ... | 0 | 0 | ['C'] | 0 |
minimum-initial-energy-to-finish-tasks | In C++ | in-c-by-ranjithgopinath-f526 | 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 | RanjithGopinath | NORMAL | 2024-10-06T14:33:06.452221+00:00 | 2024-10-06T14:33:06.452251+00:00 | 0 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['C++'] | 0 |
minimum-initial-energy-to-finish-tasks | 💥 Beats 100% on runtime and memory [EXPLAINED] | beats-100-on-runtime-and-memory-explaine-immb | Intuition\nThe problem revolves around managing energy effectively while completing tasks. Each task requires a minimum energy to start and consumes a certain a | r9n | NORMAL | 2024-10-01T21:31:47.528212+00:00 | 2024-10-01T21:31:47.528245+00:00 | 1 | false | # Intuition\nThe problem revolves around managing energy effectively while completing tasks. Each task requires a minimum energy to start and consumes a certain amount of energy. If your current energy is insufficient for a task, you need to ensure you start with enough energy to complete all tasks without running out.... | 0 | 0 | ['TypeScript'] | 0 |
minimum-initial-energy-to-finish-tasks | Beats 99% CPP Solution Easy to Understand | beats-99-cpp-solution-easy-to-understand-xuln | 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 | kingsenior | NORMAL | 2024-09-17T05:57:42.243863+00:00 | 2024-09-17T05:57:42.243892+00:00 | 3 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['C++'] | 0 |
minimum-initial-energy-to-finish-tasks | Sort Only, simple Solution, beats 95% | sort-only-simple-solution-beats-95-by-ts-5gbj | Intuition\nWe sort the tasks by the differential between actual and minimum. Then the smallest differential will be the latest tasks we finished. Because we wan | tsengh2 | NORMAL | 2024-07-18T23:59:56.091792+00:00 | 2024-07-18T23:59:56.091818+00:00 | 35 | false | # Intuition\nWe sort the tasks by the differential between actual and minimum. Then the smallest differential will be the latest tasks we finished. Because we want the remain energy as fewer as better. Then we just choose to add up the actual energy if the remain energy is able to start the task or set the energy to th... | 0 | 0 | ['Python3'] | 0 |
minimum-initial-energy-to-finish-tasks | C++ Greedy Algorithm with Custom Sorting | c-greedy-algorithm-with-custom-sorting-b-2emy | Intuition\nThe key insight is to prioritize tasks that have a larger gap between their minimum required effort and actual cost. By tackling these "high-demand" | orel12 | NORMAL | 2024-07-10T19:26:07.205594+00:00 | 2024-07-10T19:26:07.205619+00:00 | 8 | false | # Intuition\nThe key insight is to prioritize tasks that have a larger gap between their minimum required effort and actual cost. By tackling these "high-demand" tasks first, we can minimize the initial energy required.\n\n# Approach\n1. Sort tasks: Arrange tasks in descending order based on the difference between mini... | 0 | 0 | ['C++'] | 0 |
minimum-initial-energy-to-finish-tasks | Greedy approach. Sorted using comparator.C++ | greedy-approach-sorted-using-comparatorc-c5w1 | Intuition\nThe more you energyyou save from the current task can be used later on.Simple greedy approach\n\n# Approach\nUsed a comparator to sort the tasks vect | anubhavkrishna | NORMAL | 2024-07-09T21:07:38.471877+00:00 | 2024-07-09T21:07:38.471902+00:00 | 4 | false | # Intuition\nThe more you energyyou save from the current task can be used later on.Simple greedy approach\n\n# Approach\nUsed a comparator to sort the tasks vector according to the differnce of mininum and actual energy required\n\n# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\n<!-- Add your space ... | 0 | 0 | ['Greedy', 'Sorting', 'C++'] | 0 |
minimum-initial-energy-to-finish-tasks | Easy C++ Solution|| Sorting || Binary search | easy-c-solution-sorting-binary-search-by-j7n7 | 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 | ak3177590 | NORMAL | 2024-06-05T17:43:47.212840+00:00 | 2024-06-05T17:43:47.212872+00:00 | 5 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['C++'] | 0 |
minimum-initial-energy-to-finish-tasks | Solution Minimum Initial Energy to Finish Tasks | solution-minimum-initial-energy-to-finis-k70x | 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 | Suyono-Sukorame | NORMAL | 2024-05-31T01:43:18.545716+00:00 | 2024-05-31T01:43:18.545733+00:00 | 0 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['PHP'] | 0 |
minimum-initial-energy-to-finish-tasks | GREEDY || Custom Sorting || Explained | greedy-custom-sorting-explained-by-rasto-j00l | Complexity\n- Time complexity: O(n*log(n)) \n\n- Space complexity: O(1) \n\n# Code\n\nclass Solution {\npublic:\n int minimumEffort(vector<vector<int>>& task | coder_rastogi_21 | NORMAL | 2024-04-20T18:40:15.839168+00:00 | 2024-04-20T18:40:15.839195+00:00 | 4 | false | # Complexity\n- Time complexity: $$O(n*log(n))$$ \n\n- Space complexity: $$O(1)$$ \n\n# Code\n```\nclass Solution {\npublic:\n int minimumEffort(vector<vector<int>>& tasks) {\n //sort in decsending order of difference between minimum and actual energy\n sort(tasks.begin(),tasks.end(), [](vector<int>& a... | 0 | 0 | ['Greedy', 'Sorting', 'C++'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.