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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
partition-array-such-that-maximum-difference-is-k | Brute force to optimized | C++ | brute-force-to-optimized-c-by-tusharbhar-8v4w | Brute force (TLE)\nTime complexity: worst case - O(n ^ 2)\n\nclass Solution {\npublic:\n int partitionArray(vector<int>& nums, int k) {\n sort(nums.be | TusharBhart | NORMAL | 2022-07-08T06:55:36.503639+00:00 | 2022-07-08T06:55:36.503681+00:00 | 38 | false | # Brute force (TLE)\n*Time complexity: worst case - O(n ^ 2)*\n```\nclass Solution {\npublic:\n int partitionArray(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end());\n \n int i = 0, j = nums.size() - 1, ans = 0;\n \n while(i < nums.size()) {\n if(nums[j] - num... | 1 | 0 | ['Two Pointers', 'C', 'Sorting'] | 0 |
partition-array-such-that-maximum-difference-is-k | JAVA || SORT || BINARY SEARCH || EASY TO UNDERSTAND | java-sort-binary-search-easy-to-understa-sc64 | \nclass Solution {\n public int partitionArray(int[] nums, int k) \n {\n Arrays.sort(nums);\n \n int ans=0;\n int i=0;\n | 29nidhishah | NORMAL | 2022-06-26T16:33:09.740753+00:00 | 2022-06-26T16:33:09.740802+00:00 | 44 | false | ```\nclass Solution {\n public int partitionArray(int[] nums, int k) \n {\n Arrays.sort(nums);\n \n int ans=0;\n int i=0;\n \n while(i<nums.length)\n {\n int curr=nums[i];\n ans++; \n int pos=binarySearch(nums,i,nums[i]+k+1);\n ... | 1 | 0 | ['Sorting', 'Binary Tree', 'Java'] | 0 |
partition-array-such-that-maximum-difference-is-k | java easy to understand O(nlogn) || sorting || beginner friendly || simple approach | java-easy-to-understand-onlogn-sorting-b-16ea | class Solution {\n public int partitionArray(int[] nums, int k) {\n Arrays.sort(nums);\n int start = 0;\n int count=1;\n for(int | Nachiket_ | NORMAL | 2022-06-20T08:26:51.837905+00:00 | 2022-06-20T08:26:51.837943+00:00 | 82 | false | class Solution {\n public int partitionArray(int[] nums, int k) {\n Arrays.sort(nums);\n int start = 0;\n int count=1;\n for(int i=1;i<nums.length;i++){\n if((nums[i]-nums[start])>k){\n start = i;\n count++;\n }\n }\n retur... | 1 | 0 | ['Greedy', 'Sorting', 'Java'] | 0 |
partition-array-such-that-maximum-difference-is-k | Java - sort and compare | java-sort-and-compare-by-rohitdhiman0202-9a9f | \nclass Solution {\n public int partitionArray(int[] nums, int k) \n {\n Arrays.sort(nums);\n \n int i =1;\n int prev_val = nu | rohitdhiman0202 | NORMAL | 2022-06-18T11:17:50.976393+00:00 | 2022-06-18T11:17:50.976426+00:00 | 66 | false | ```\nclass Solution {\n public int partitionArray(int[] nums, int k) \n {\n Arrays.sort(nums);\n \n int i =1;\n int prev_val = nums[0];\n int result =1;\n \n while(i < nums.length)\n {\n if(nums[i] - prev_val > k)\n {\n r... | 1 | 0 | ['Sorting', 'Java'] | 0 |
partition-array-such-that-maximum-difference-is-k | C++ Simple Soution using Sorting | c-simple-soution-using-sorting-by-moriar-hnnc | \nint partitionArray(vector<int>& nums, int k) {\n \n sort(nums.begin(),nums.end());\n \n int res = 0 , i = 0 , j = 0 , n = nums.siz | moriarty12 | NORMAL | 2022-06-17T10:26:13.928427+00:00 | 2022-06-17T10:26:13.928497+00:00 | 86 | false | ```\nint partitionArray(vector<int>& nums, int k) {\n \n sort(nums.begin(),nums.end());\n \n int res = 0 , i = 0 , j = 0 , n = nums.size();\n \n while(j<n){\n if(nums[j]-nums[i] > k){ \n res++;\n i = j; \n }\n ... | 1 | 0 | ['C', 'Sorting', 'C++'] | 0 |
partition-array-such-that-maximum-difference-is-k | C++ || 6 Lines || Sort + 2 Pointer |Easy to Understand | c-6-lines-sort-2-pointer-easy-to-underst-vfz7 | \nclass Solution {\npublic:\n int partitionArray(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end());\n int cnt = 1,low = 0,i=0;\n\t\t/ | jayprakashray | NORMAL | 2022-06-12T05:29:37.063377+00:00 | 2022-06-12T05:29:37.063411+00:00 | 38 | false | ```\nclass Solution {\npublic:\n int partitionArray(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end());\n int cnt = 1,low = 0,i=0;\n\t\t//low points to min element and i points to max \n\t\t//whenever their difference exceeds k we update low index and increment counter\n while(i<nums.siz... | 1 | 0 | [] | 0 |
partition-array-such-that-maximum-difference-is-k | O(N) solution C++ (88ms beats 100%) and Java (11ms beats 99.73%) | on-solution-c-88ms-beats-100-and-java-11-v5zj | C++:\n\nconst int ZERO = []() {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\npublic:\n bool a[1000 | Alvanerle | NORMAL | 2022-06-11T18:15:07.734307+00:00 | 2022-06-12T09:09:37.924961+00:00 | 85 | false | C++:\n```\nconst int ZERO = []() {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\npublic:\n bool a[100005];\n \n int partitionArray(vector<int>& nums, int k) {\n int mx = -1;\n for(int num: nums){\n a[num] = 1;\n mx = ... | 1 | 0 | [] | 0 |
partition-array-such-that-maximum-difference-is-k | scala solution. | scala-solution-by-lyk4411-cv77 | \n\n def partitionArray(nums: Array[Int], k: Int): Int = {\n nums.sorted.foldLeft((1, nums.min))((acc, cur) =>{\n cur - acc._2 > k match {\n cas | lyk4411 | NORMAL | 2022-06-11T08:13:00.819270+00:00 | 2022-06-11T08:13:38.474979+00:00 | 40 | false | ```\n\n def partitionArray(nums: Array[Int], k: Int): Int = {\n nums.sorted.foldLeft((1, nums.min))((acc, cur) =>{\n cur - acc._2 > k match {\n case true => (acc._1 + 1, cur)\n case _ => acc\n }\n })._1\n }\n``` | 1 | 0 | ['Scala'] | 1 |
partition-array-such-that-maximum-difference-is-k | 2 pointers C++ | 2-pointers-c-by-its_dark-cliz | class Solution {\npublic:\n\n int partitionArray(vector& nums, int k) {\n sort(nums.begin(),nums.end());\n int i=0,j=0,ans=0;\n while(i< | its_Dark_ | NORMAL | 2022-06-08T08:33:54.162348+00:00 | 2022-06-08T08:33:54.162393+00:00 | 67 | false | class Solution {\npublic:\n\n int partitionArray(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end());\n int i=0,j=0,ans=0;\n while(i<nums.size()&&j<nums.size()){\n if(nums[j]-nums[i]<=k)j++;\n else {\n i=j;\n ans++;\n }\n ... | 1 | 0 | [] | 0 |
partition-array-such-that-maximum-difference-is-k | [c++] | c-by-svik510-isvq | \tPartition Array Such That Maximum Difference Is K\nclass Solution {\npublic:\n \n int i=0,j=i+1,count=1;\n int length=nums.size();\n | svik510 | NORMAL | 2022-06-07T16:36:40.109036+00:00 | 2022-06-07T16:36:40.109084+00:00 | 47 | false | \tPartition Array Such That Maximum Difference Is K\nclass Solution {\npublic:\n \n int i=0,j=i+1,count=1;\n int length=nums.size();\n sort(nums.begin(),nums.end());\n while(j<length)\n {\n if(nums[j]-nums[i]>k)\n {\n count++;\n ... | 1 | 0 | ['Two Pointers'] | 0 |
partition-array-such-that-maximum-difference-is-k | Queue & Sorting Approach in Partition Array | queue-sorting-approach-in-partition-arra-prys | Priority Queue TC:- O(n log n)\n\nclass Solution {\n public int partitionArray(int[] nums, int k) {\n return usePriorityQueue(nums, k);\n }\n \ | batman005 | NORMAL | 2022-06-06T03:46:36.434659+00:00 | 2022-06-06T03:46:36.434708+00:00 | 54 | false | Priority Queue TC:- O(n log n)\n```\nclass Solution {\n public int partitionArray(int[] nums, int k) {\n return usePriorityQueue(nums, k);\n }\n \n public int usePriorityQueue(int[] nums, int k) {\n PriorityQueue<Integer> p = new PriorityQueue<>();\n for(int num : nums){\n p.offer(nu... | 1 | 0 | ['Heap (Priority Queue)', 'Java'] | 0 |
partition-array-such-that-maximum-difference-is-k | Python | python-by-hong_zhao-pk2e | python\n nums.sort()\n left = res = 0\n for right in range(len(nums)):\n if nums[right] - nums[left] > k:\n res + | hong_zhao | NORMAL | 2022-06-06T01:20:36.957626+00:00 | 2022-06-06T01:20:36.957660+00:00 | 55 | false | ```python\n nums.sort()\n left = res = 0\n for right in range(len(nums)):\n if nums[right] - nums[left] > k:\n res += 1\n left = right\n return res + 1\n``` | 1 | 0 | ['Python'] | 0 |
partition-array-such-that-maximum-difference-is-k | JavaScript - 100% Simple & Fastest O(nlogn) | javascript-100-simple-fastest-onlogn-by-t89d7 | \n/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar partitionArray = function(nums, k) {\n nums.sort((a, b) => a- b)\n l | Asiful_Islam_Sakib | NORMAL | 2022-06-05T15:10:46.787438+00:00 | 2022-06-07T16:08:32.643497+00:00 | 66 | false | ```\n/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar partitionArray = function(nums, k) {\n nums.sort((a, b) => a- b)\n let start = nums[0]\n let count = 0\n for(let i = 1; i < nums.length; i++){\n if(nums[i] - start > k){\n count++\n start = ... | 1 | 1 | ['Sorting', 'JavaScript'] | 2 |
partition-array-such-that-maximum-difference-is-k | java solution by sorting the array | java-solution-by-sorting-the-array-by-ra-8k8b | \nclass Solution {\n public int partitionArray(int[] nums, int k) {\n Arrays.sort(nums);\n int partition=0;\n int start=0;\n for( | Rakesh_Sharma_4 | NORMAL | 2022-06-05T14:15:50.851705+00:00 | 2022-06-05T14:15:50.851749+00:00 | 30 | false | ```\nclass Solution {\n public int partitionArray(int[] nums, int k) {\n Arrays.sort(nums);\n int partition=0;\n int start=0;\n for(int i=0;i<nums.length;++i)\n {\n if(nums[i]-nums[start]<=k)\n {\n if(i==nums.length-1)\n {\n ... | 1 | 0 | ['Java'] | 0 |
partition-array-such-that-maximum-difference-is-k | C++ | Sorting | Greedy | c-sorting-greedy-by-i_love_dua_lipa-xh1h | Approach :\nIn problem statement, it states that min and max of every subsequence should have difference of at most k. First thing that comes to mind is to coll | coder_with_dimples | NORMAL | 2022-06-05T12:53:08.419026+00:00 | 2022-06-05T12:53:08.419071+00:00 | 43 | false | **Approach** :\nIn problem statement, it states that min and max of every subsequence should have difference of at most k. First thing that comes to mind is to collect all elements that are in each other\'s vicinity. Since here vicinity is matter of difference, best way to collect these elements is sorting. \n\nNow, fo... | 1 | 0 | ['Two Pointers', 'C', 'Sorting'] | 0 |
partition-array-such-that-maximum-difference-is-k | C++ || Sorting || Binary Search | c-sorting-binary-search-by-arceus55-xhj1 | ```\nint binarySearch(int low,int high,vector&nums, int k,int left){\n int ans;\n while(low<=high){\n int mid = (low+high)/2;\n | arceus55 | NORMAL | 2022-06-05T11:55:39.537478+00:00 | 2022-06-05T11:56:41.695511+00:00 | 24 | false | ```\nint binarySearch(int low,int high,vector<int>&nums, int k,int left){\n int ans;\n while(low<=high){\n int mid = (low+high)/2;\n if(nums[mid]-left<=k){\n ans = mid;\n low=mid+1;\n }\n else{\n high=mid-1;\n ... | 1 | 0 | [] | 0 |
partition-array-such-that-maximum-difference-is-k | Easy java solution | easy-java-solution-by-nisthaagarwal-ljg1 | \nclass Solution {\n public int partitionArray(int[] nums, int k) {\n if(nums== null || nums.length==0) return 0;\n Arrays.sort(nums);\n | nisthaagarwal | NORMAL | 2022-06-05T11:54:08.632326+00:00 | 2022-06-05T11:54:08.632371+00:00 | 38 | false | ```\nclass Solution {\n public int partitionArray(int[] nums, int k) {\n if(nums== null || nums.length==0) return 0;\n Arrays.sort(nums);\n int count=1;\n int min= Integer.MAX_VALUE;\n int max= Integer.MIN_VALUE;\n for(int val: nums){\n min= Math.min(val, min);\n ... | 1 | 0 | ['Java'] | 0 |
partition-array-such-that-maximum-difference-is-k | ✅. | C++ | Faster than 100% | Easy - Understanding | c-faster-than-100-easy-understanding-by-45t8r | As they asked for only number of subsequences, we should\'nt worry about the order of the elements, thus we can sort the nums array.\n\nnow we take 2 variables, | starkster | NORMAL | 2022-06-05T08:44:29.065259+00:00 | 2022-06-05T08:44:29.065297+00:00 | 28 | false | **As they asked for only number of subsequences, we should\'nt worry about the order of the elements, thus we can sort the nums array.**\n\nnow we take 2 variables, start and next, initially both are set to 0\nnow we loop until start < n, else it\'ll be out of bounds\n\nwe keep on increasing the next pointer, if \n1. i... | 1 | 0 | ['C', 'Sorting'] | 1 |
partition-array-such-that-maximum-difference-is-k | O(N)||C++||SORT||SELECT||EASY UNDERSTANDING||FULL EXPLAINED | oncsortselecteasy-understandingfull-expl-w92u | Just sort the given array and keep track of the minimum and maximum element. When the minimum element changes, you make an extra subsequence. The minimum elemen | adbnemesis | NORMAL | 2022-06-05T08:07:05.051484+00:00 | 2022-06-05T08:07:05.051523+00:00 | 37 | false | Just sort the given array and keep track of the minimum and maximum element. When the minimum element changes, you make an extra subsequence. The minimum element is changed the moment when nums[i]-min > k\n\n```\nclass Solution {\npublic:\n int partitionArray(vector<int>& nums, int k) {\n sort(begin(nums),end... | 1 | 0 | ['C', 'Sorting'] | 0 |
partition-array-such-that-maximum-difference-is-k | Simple 5 line code || c++ | simple-5-line-code-c-by-jainss-1i4l | \nclass Solution {\npublic:\n int partitionArray(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end());\n int ans=0,j=0;\n for(int | jainss | NORMAL | 2022-06-05T08:04:46.098096+00:00 | 2022-06-05T08:04:46.098141+00:00 | 31 | false | ```\nclass Solution {\npublic:\n int partitionArray(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end());\n int ans=0,j=0;\n for(int i=1;i<nums.size();i++){\n if(nums[i]-nums[j]>k){\n ans++;\n j=i;\n }\n }\n return ans+1;\n... | 1 | 0 | ['C', 'Sorting'] | 0 |
partition-array-such-that-maximum-difference-is-k | C++ Greedy | c-greedy-by-arrxy-7b1d | We need to find subsequence so we can sort the array and use sliding window to keep check for max - min, whenever it exceeds we increment cnt by 1 and change th | arrxy | NORMAL | 2022-06-05T07:14:32.971875+00:00 | 2022-06-05T07:15:13.739752+00:00 | 47 | false | We need to find subsequence so we can sort the array and use sliding window to keep check for max - min, whenever it exceeds we increment cnt by 1 and change the lo pointer\n```\nclass Solution {\npublic:\n\tint partitionArray(vector<int>& nums, int k) {\n\t\tsort(nums.begin(), nums.end());\n\t\tint cnt = 1, n = nums.s... | 1 | 0 | ['Greedy', 'C', 'Sliding Window'] | 0 |
partition-array-such-that-maximum-difference-is-k | C++ Easy | Sorting | Full explanation | Intution | c-easy-sorting-full-explanation-intution-1332 | Task:\n\nReturn\xA0the\xA0minimum\xA0number of subsequences needed such that the difference between the maximum and minimum values in each subsequence is\xA0at | tejasmn | NORMAL | 2022-06-05T06:58:36.349546+00:00 | 2022-06-05T07:07:18.487882+00:00 | 37 | false | **Task:**\n\nReturn\xA0the\xA0minimum\xA0number of subsequences needed such that the difference between the maximum and minimum values in each subsequence is\xA0at most\xA0k.\n\n**Constraints:**\n\nlength<=10^5\nSo (10^5)^2 = 10^10 is not possible i.e O(n^2) fails.\nWe need to think in O(nlogn) or O(logn) or O(n)\ni.e ... | 1 | 0 | ['Sorting'] | 0 |
maximum-number-of-tasks-you-can-assign | [Python] greedy + binary search, explained | python-greedy-binary-search-explained-by-sas1 | The idea of this problem is the following: let us ask question: check(k): can we finish k tasks or not. Here is a couple of insights.\n\n1. If we want to finish | dbabichev | NORMAL | 2021-11-13T16:23:10.324774+00:00 | 2021-11-13T16:42:25.862034+00:00 | 6,283 | false | The idea of this problem is the following: let us ask question: `check(k)`: can we finish `k` tasks or not. Here is a couple of insights.\n\n1. If we want to finish `k` tasks, we better choose the smallest `k` of them.\n2. If we want to finish `k` tasks, we need `k` workers, and we want to choost the `k` strongest of t... | 82 | 4 | ['Binary Search', 'Greedy'] | 18 |
maximum-number-of-tasks-you-can-assign | [C++] | Binary Search + Intuitive Greedy Idea | Detailed Explanation + Comments | c-binary-search-intuitive-greedy-idea-de-66tm | Idea\nThis is a good problem which requires concepts of binary search as well as greedy. I am going to try to explain the solution in points for better understa | astroash | NORMAL | 2021-11-13T16:01:20.369927+00:00 | 2021-11-13T16:57:06.616750+00:00 | 5,794 | false | **Idea**\nThis is a good problem which requires concepts of binary search as well as greedy. I am going to try to explain the solution in points for better understanding. \n\n* We binary seach over the number of tasks to be completed. Hence the search space would be [0, min(workers.size(), tasks.size()]. \n* Let us say... | 70 | 1 | ['Binary Search', 'Greedy'] | 9 |
maximum-number-of-tasks-you-can-assign | Assign m easiest tasks | assign-m-easiest-tasks-by-votrubac-ki10 | Liked this one. The binary search approach is not very obvious here.\n\nThe idea is to pick m easiest tasks, and m strongest workers, and see if we can assign t | votrubac | NORMAL | 2021-11-14T23:20:01.615192+00:00 | 2021-11-14T23:20:50.713217+00:00 | 4,170 | false | Liked this one. The binary search approach is not very obvious here.\n\nThe idea is to pick `m` easiest tasks, and `m` strongest workers, and see if we can assign those tasks.\n\nWith this set of `m` workers and tasks, we:\n1. Process tasks from hardest to easiest\n2. Check if the strongest worker can do the hardest of... | 48 | 1 | [] | 5 |
maximum-number-of-tasks-you-can-assign | JAVA Solution with Monotonic Queue | java-solution-with-monotonic-queue-by-jw-vrsp | \nclass Solution {\n public int maxTaskAssign(int[] tasks, int[] workers, int pills, int strength) {\n int left = 0, right = Math.min(tasks.length, wo | jw84 | NORMAL | 2021-12-08T04:55:36.159380+00:00 | 2021-12-08T04:55:36.159431+00:00 | 2,003 | false | ```\nclass Solution {\n public int maxTaskAssign(int[] tasks, int[] workers, int pills, int strength) {\n int left = 0, right = Math.min(tasks.length, workers.length);\n Arrays.sort(tasks);\n Arrays.sort(workers);\n while(left+1<right)\n {\n int mid = left + (right - lef... | 27 | 0 | [] | 5 |
maximum-number-of-tasks-you-can-assign | Python | Binary Search + Check Answer Greedily | python-binary-search-check-answer-greedi-roc4 | Observation 1:\nIf we know how many tasks can be assigned (i.e. we know the ans = k in advanced), the best way to choose tasks and workers is:\n * Choose the | zoo30215 | NORMAL | 2021-11-13T16:10:33.644169+00:00 | 2021-11-14T08:41:19.579068+00:00 | 1,684 | false | * Observation 1:\nIf we know how many tasks can be assigned (i.e. we know the `ans = k` in advanced), the best way to choose tasks and workers is:\n * Choose the `k` smallest tasks.\n * Choose the `k` strongest workers.\n * For example, if we need to finish `3` tasks among `tasks = [5,5,8,9,9]` with `workers =... | 26 | 0 | [] | 4 |
maximum-number-of-tasks-you-can-assign | C++ Why Binary Search? | c-why-binary-search-by-changoi-990r | Why Binary Search?\nWhenever the set of all possible values that can satisfy the requirements form a continuous range, we apply the binary search to find the op | changoi | NORMAL | 2021-11-13T17:22:57.954082+00:00 | 2021-11-14T02:26:33.540540+00:00 | 2,006 | false | **Why Binary Search?**\nWhenever the set of all possible values that can satisfy the requirements form a continuous range, we apply the binary search to find the optimal value out of those.\n\nLet\'s understand this with the current example.\n\n- Suppose someone says that you can complete K tasks with this particular i... | 21 | 0 | [] | 3 |
maximum-number-of-tasks-you-can-assign | [C++] Binary search the answer | c-binary-search-the-answer-by-tudor67-ot9a | \u2714\uFE0F Solution 1 (Binary search the answer)\nThis is a nice problem which can be solved with binary search.\n\nMain ideas\n Observation 1\n\t Let\'s say | tudor67 | NORMAL | 2021-11-25T21:29:47.254611+00:00 | 2021-11-26T10:37:19.652559+00:00 | 1,458 | false | ## \u2714\uFE0F **Solution 1 (Binary search the answer)**\nThis is a nice problem which can be solved with binary search.\n\n**Main ideas**\n* Observation 1\n\t* Let\'s say that we have a method `isValid(k)` which returns true if the workers can complete k tasks\n(such that all conditions of the problem are satisfied) ... | 18 | 1 | ['Greedy', 'C', 'Binary Tree'] | 1 |
maximum-number-of-tasks-you-can-assign | [python] binary search + greedy with deque O(nlogn) | python-binary-search-greedy-with-deque-o-81bw | Use binary search with greedy check. Each check can be done in O(n) using a deque. Within a check, we iterate through the workers from the weakiest to the stron | hkwu6013 | NORMAL | 2021-11-20T16:13:00.963742+00:00 | 2021-11-20T16:14:05.084106+00:00 | 1,038 | false | Use binary search with greedy check. Each check can be done in O(n) using a deque. Within a check, we iterate through the workers from the weakiest to the strongest. Each worker needs to take a task. \nThere are two cases:\n1. The worker can take the easiest task available: we assign it to the worker.\n2. The worker ca... | 16 | 0 | ['Greedy', 'Binary Tree', 'Python3'] | 2 |
maximum-number-of-tasks-you-can-assign | [Python3] binary search | python3-binary-search-by-ye15-cdjc | I thought a greedy algo would be enough but have spent hours and couldn\'t get a solution. It turns out that the direction was wrong in the first place. Below i | ye15 | NORMAL | 2021-11-13T22:16:41.038271+00:00 | 2021-11-14T01:47:50.231819+00:00 | 1,094 | false | I thought a greedy algo would be enough but have spent hours and couldn\'t get a solution. It turns out that the direction was wrong in the first place. Below implementation is based on other posts in the discuss. \n\nPlease check out this [commit](https://github.com/gaosanyong/leetcode/commit/e61879b77928a08bb15cc182a... | 11 | 0 | ['Python3'] | 5 |
maximum-number-of-tasks-you-can-assign | Greedy, sorting, binary search and array [EXPLAINED] | greedy-sorting-binary-search-and-array-e-2na5 | Intuition\nAssign as many tasks as possible to workers, utilizing their strength and the option to use pills to temporarily boost their capacity. By sorting the | r9n | NORMAL | 2024-10-25T06:07:39.594573+00:00 | 2024-10-25T06:07:39.594602+00:00 | 171 | false | # Intuition\nAssign as many tasks as possible to workers, utilizing their strength and the option to use pills to temporarily boost their capacity. By sorting the tasks and workers, we can efficiently match them based on their abilities while considering the limits imposed by the pills.\n\n# Approach\nSort the tasks an... | 8 | 0 | ['TypeScript'] | 0 |
maximum-number-of-tasks-you-can-assign | [Python Binary Search + Monotonic Queue] Template | python-binary-search-monotonic-queue-tem-hrsx | \nfrom collections import deque\nclass Solution:\n def maxTaskAssign(self, tasks: List[int], workers: List[int], pills: int, strength: int) -> int:\n | surface09 | NORMAL | 2022-03-26T21:32:16.431207+00:00 | 2022-05-26T20:59:06.467452+00:00 | 665 | false | ```\nfrom collections import deque\nclass Solution:\n def maxTaskAssign(self, tasks: List[int], workers: List[int], pills: int, strength: int) -> int:\n \n tasks.sort()\n workers.sort()\n \n def can_finish(mid, pills):\n \n n = len(workers)\n \n ... | 4 | 0 | ['Binary Search', 'Python'] | 1 |
maximum-number-of-tasks-you-can-assign | why binary search and why not direct greedy approach? EXPLAINED | why-binary-search-and-why-not-direct-gre-o0z5 | greedy approach will not work here why? read below\n\ne.x if we prioritize on the basis of workers array , the worker[i] will try to do the work just smaller th | vikassingh2810 | NORMAL | 2022-01-31T14:37:20.055135+00:00 | 2022-02-02T05:40:31.678599+00:00 | 427 | false | greedy approach will not work here why? read below\n\ne.x if we prioritize on the basis of workers array , the worker[i] will try to do the work just smaller then its strenght \nbut the problem occur when a worker can do a task with and without a pill :\n\nfor e g \n\ntask [ 8 5 5 ]\nworker [ 6 6 4 ]\npill =1\nstre =... | 4 | 0 | [] | 0 |
maximum-number-of-tasks-you-can-assign | [Python] Binary Search with Double Deque to Trace Available Workers | python-binary-search-with-double-deque-t-5axv | Explained in the comments:\n\nclass Solution:\n def maxTaskAssign(self, tasks: List[int], workers: List[int], pills: int, strength: int) -> int:\n tas | alenny | NORMAL | 2021-12-13T02:19:32.256138+00:00 | 2021-12-13T02:19:32.256164+00:00 | 338 | false | Explained in the comments:\n```\nclass Solution:\n def maxTaskAssign(self, tasks: List[int], workers: List[int], pills: int, strength: int) -> int:\n tasks = list(sorted(tasks))\n workers = list(sorted(workers))\n WN = len(workers)\n \n # to evaluate if k tasks can be done, we just... | 3 | 0 | [] | 0 |
maximum-number-of-tasks-you-can-assign | C++ greedy without binary-search | c-greedy-without-binary-search-by-mrsuyi-kdpn | I would say binary search is a much better solution... but still it\'s possible to use greedy only.\n\n1. Sort tasks in increasing order. Put workers in a set s | mrsuyi | NORMAL | 2021-11-22T00:23:56.812298+00:00 | 2021-11-23T04:39:41.279904+00:00 | 554 | false | I would say binary search is a much better solution... but still it\'s possible to use greedy only.\n\n1. Sort `tasks` in increasing order. Put `workers` in a set `st` as a pool of candidate workers.\n2. Keep a set `taken` of workers which have taken a pill to match a task.\n3. Loop through `tasks` from biggest to smal... | 3 | 1 | [] | 2 |
maximum-number-of-tasks-you-can-assign | ✅ [Python] Binary Search || Faster than 100% || Easy to Understand with Explanation | python-binary-search-faster-than-100-eas-utfz | \nclass Solution(object):\n def maxTaskAssign(self, tasks, workers, pills, strength):\n def canAssignAll(tasks, workers, pills):\n # notic | linfq | NORMAL | 2021-11-19T03:55:30.948052+00:00 | 2021-11-19T07:14:57.613297+00:00 | 488 | false | ```\nclass Solution(object):\n def maxTaskAssign(self, tasks, workers, pills, strength):\n def canAssignAll(tasks, workers, pills):\n # notice that len(tasks) = len(workers)\n # given pills and strength, can all tasks be assigned, so that every worker has a task.\n while len... | 3 | 0 | [] | 1 |
maximum-number-of-tasks-you-can-assign | Python | Easy | Queue | Maximum Number of Tasks You Can Assign | python-easy-queue-maximum-number-of-task-vxgj | \nsee the Successfully Accepted Submission\nPython\nfrom sortedcontainers import SortedList\n\nclass Solution:\n def maxTaskAssign(self, tasks, workers, p, s | Khosiyat | NORMAL | 2023-10-11T15:19:26.888013+00:00 | 2023-10-11T15:19:26.888030+00:00 | 246 | false | \n[see the Successfully Accepted Submission](https://leetcode.com/submissions/detail/1071707824/)\n```Python\nfrom sortedcontainers import SortedList\n\nclass Solution:\n def maxTaskAssign(self, tasks, workers, p, strength):\n n = len(tasks)\n m = len(workers)\n\n # Sorting the tasks and workers... | 2 | 0 | ['Queue', 'Python'] | 0 |
maximum-number-of-tasks-you-can-assign | 🔥🔥🔥C++ | super easy | clean code | multi set | easy to grasp🔥🔥🔥 | c-super-easy-clean-code-multi-set-easy-t-166f | 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 | Algo-Messihas | NORMAL | 2023-08-13T16:06:04.471504+00:00 | 2023-08-13T16:06:04.471538+00:00 | 767 | 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 |
maximum-number-of-tasks-you-can-assign | [Javascript] Binary Search & Deque | javascript-binary-search-deque-by-anna-h-m5vb | Solution: Binary Search & Deque\n\nBinary search for the largest number of tasks that can be completed.\nHow to check whether we can complete k tasks:\n Try t | anna-hcj | NORMAL | 2022-10-30T10:13:30.016231+00:00 | 2022-10-30T10:13:56.304597+00:00 | 160 | false | **Solution: Binary Search & Deque**\n\nBinary search for the largest number of tasks that can be completed.\nHow to check whether we can complete k tasks:\n* Try to assign the k weakest tasks to the k strongest workers.\n* Sort tasks in asc order and workers in desc order.\n* Go through the workers from weakest t... | 2 | 0 | ['JavaScript'] | 0 |
maximum-number-of-tasks-you-can-assign | [C++] | Binary Search | Noob Friendly | c-binary-search-noob-friendly-by-grimo-i9ht | \nclass Solution {\npublic:\n bool isPossible(int noOfTasks,vector<int>& tasks, vector<int>& workers, int pills, int strength){\n multiset <int> ms(wo | grimo | NORMAL | 2022-06-14T22:16:04.661942+00:00 | 2022-06-14T22:16:04.661966+00:00 | 612 | false | ```\nclass Solution {\npublic:\n bool isPossible(int noOfTasks,vector<int>& tasks, vector<int>& workers, int pills, int strength){\n multiset <int> ms(workers.end()-noOfTasks,workers.end());\n for(int i=noOfTasks-1;i>=0;i--){\n //get the strongest worker\n auto it = ms.end();\n ... | 2 | 0 | ['Greedy', 'Binary Tree'] | 0 |
maximum-number-of-tasks-you-can-assign | Java | TreeMap | Binary Search | java-treemap-binary-search-by-6862wins-qrla | ```\n public int maxTaskAssign(int[] tasks, int[] workers, int pills, int strength) {\n Arrays.sort(tasks);\n TreeMap map = new TreeMap<>();\n | 6862wins | NORMAL | 2022-01-29T06:12:37.134964+00:00 | 2022-01-29T06:12:37.134994+00:00 | 545 | false | ```\n public int maxTaskAssign(int[] tasks, int[] workers, int pills, int strength) {\n Arrays.sort(tasks);\n TreeMap<Integer, Integer> map = new TreeMap<>();\n for (int i : workers)\n \tmap.put(i, map.getOrDefault(i, 0) + 1);\n int res = 0, left = 0, right = Math.min(tasks.length,... | 2 | 0 | ['Binary Search', 'Tree', 'Java'] | 0 |
maximum-number-of-tasks-you-can-assign | Greedy Binary Search Java Solution | greedy-binary-search-java-solution-by-lu-fta1 | \n\nclass Solution {\n public int maxTaskAssign(int[] tasks, int[] workers, int pills, int strength) {\n Arrays.sort(tasks);\n Arrays.sort(work | luciddream | NORMAL | 2022-01-08T09:33:21.399511+00:00 | 2022-01-08T09:38:02.180023+00:00 | 454 | false | \n```\nclass Solution {\n public int maxTaskAssign(int[] tasks, int[] workers, int pills, int strength) {\n Arrays.sort(tasks);\n Arrays.sort(workers);\n int m = tasks.length, n = workers.length;\n int start = 0, end = Math.min(m, n);\n while(start < end) {\n int mid = (... | 2 | 0 | ['Java'] | 0 |
maximum-number-of-tasks-you-can-assign | Java Easy Solution + Explanation | java-easy-solution-explanation-by-octavi-huoq | Approach:\n1. So we know that the min task that can be done is 0 and the max task that can be done is min size between worker or tasks. \n2. Sort both arrays no | Octavius25 | NORMAL | 2021-11-28T08:42:13.561778+00:00 | 2021-11-28T08:42:13.561810+00:00 | 575 | false | **Approach:**\n**1. So we know that the min task that can be done is 0 and the max task that can be done is min size between worker or tasks. \n2. Sort both arrays now using binary search we need to find that a whether he is able to complete task(low+high)/2 or not if he is able to complete that task then try for some... | 2 | 0 | ['Greedy', 'Binary Tree'] | 1 |
maximum-number-of-tasks-you-can-assign | [golang] binary search + greedy check | golang-binary-search-greedy-check-by-kee-h34c | \nfunc maxTaskAssign(tasks []int, workers []int, pills int, strength int) int {\n sort.Ints(tasks)\n sort.Ints(workers)\n\n l, h := 0, min(len(tasks), | keemzen | NORMAL | 2021-11-16T23:15:58.983901+00:00 | 2021-11-16T23:15:58.983929+00:00 | 231 | false | ```\nfunc maxTaskAssign(tasks []int, workers []int, pills int, strength int) int {\n sort.Ints(tasks)\n sort.Ints(workers)\n\n l, h := 0, min(len(tasks), len(workers))\n for l <= h {\n m := (l + h) / 2\n if check(tasks[0:m], workers[len(workers)-m:], pills, strength) {\n l = m + 1\n... | 2 | 0 | ['Binary Search', 'Go'] | 2 |
maximum-number-of-tasks-you-can-assign | nlgn Greedy Solution (can pass all tests but i'm not sure it's correct) | nlgn-greedy-solution-can-pass-all-tests-0v5ux | \n public int maxTaskAssign(int[] tasks, int[] workers, int pills, int strength) {\n Arrays.sort(tasks);\n Arrays.sort(workers);\n boole | nervose | NORMAL | 2021-11-14T09:43:38.952906+00:00 | 2021-11-14T10:08:07.731932+00:00 | 428 | false | ```\n public int maxTaskAssign(int[] tasks, int[] workers, int pills, int strength) {\n Arrays.sort(tasks);\n Arrays.sort(workers);\n boolean[]usedWorkerInFirstRound=new boolean[workers.length];\n int maxPossibleUsedTaskLen=Math.min(tasks.length,workers.length);\n int curToJudgeWor... | 2 | 0 | ['Greedy', 'Java'] | 1 |
maximum-number-of-tasks-you-can-assign | (C++) 2071. Maximum Number of Tasks You Can Assign | c-2071-maximum-number-of-tasks-you-can-a-ufh3 | \n\nclass Solution {\npublic:\n int maxTaskAssign(vector<int>& tasks, vector<int>& workers, int pills, int strength) {\n sort(tasks.begin(), tasks.end | qeetcode | NORMAL | 2021-11-13T23:28:21.768299+00:00 | 2021-11-13T23:28:21.768327+00:00 | 521 | false | \n```\nclass Solution {\npublic:\n int maxTaskAssign(vector<int>& tasks, vector<int>& workers, int pills, int strength) {\n sort(tasks.begin(), tasks.end()); \n sort(workers.begin(), workers.end()); \n \n auto fn = [&](int k) {\n int p = pills; \n multiset<int> st(wo... | 2 | 0 | ['C'] | 1 |
maximum-number-of-tasks-you-can-assign | [C++] 132 ms/100%, O((n+m) * log(min(n, m)) ), no multiset. | c-132-ms100-onm-logminn-m-no-multiset-by-8nbg | Main ideas are the same as in solutions with multiset (upgraded with a final idea of 3 pointers+deque).\n\n\nstatic const int __ = []() { std::ios::sync_with_st | a_le_k | NORMAL | 2021-11-13T16:47:17.234232+00:00 | 2021-11-13T18:08:37.866353+00:00 | 390 | false | Main ideas are the same as in solutions with multiset (upgraded with a final idea of 3 pointers+deque).\n\n```\nstatic const int __ = []() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); return 0; }();\n\nconstexpr int MX=50\'000;\nbool used[MX];\n\nstruct array_deque\n{\n int vals... | 2 | 2 | [] | 2 |
maximum-number-of-tasks-you-can-assign | Java Binary Search + TreeMap Solution with comments | java-binary-search-treemap-solution-with-qyt9 | So if you want to find maximum number of tasks that can be completed with given sets of workers, tasks and pills we can divide the problem in following way \n\n | pathey | NORMAL | 2024-11-18T19:22:30.032516+00:00 | 2024-11-18T19:22:30.032539+00:00 | 170 | false | So if you want to find maximum number of tasks that can be completed with given sets of workers, tasks and pills we can divide the problem in following way \n\n1) First if we are given n (The maximum number of tasks we can finish can we check if it possible to finish n tasks with workers & pills)\n2) If we can efficien... | 1 | 0 | ['Tree', 'Binary Tree', 'Java'] | 0 |
maximum-number-of-tasks-you-can-assign | EASY SOLUTION || CLEAN CODE | easy-solution-clean-code-by-udittyagi07-nl7v | \n# Code\n\nclass Solution {\npublic:\n bool check(vector<int>& tasks, vector<int>& workers, int pills, int strength,int index)\n {\n multiset<int> | udittyagi07 | NORMAL | 2024-05-07T06:54:12.915605+00:00 | 2024-05-07T06:54:12.915640+00:00 | 166 | false | \n# Code\n```\nclass Solution {\npublic:\n bool check(vector<int>& tasks, vector<int>& workers, int pills, int strength,int index)\n {\n multiset<int> st;\n for(auto it:workers)\n {\n st.insert(it);\n }\n for(int i=index-1;i>=0;i--)\n {\n auto it=st.... | 1 | 0 | ['C++'] | 1 |
maximum-number-of-tasks-you-can-assign | 🔥🔥C++ | Intuition + Approach | multi set + Binary Search | Easy to understand🔥🔥 | c-intuition-approach-multi-set-binary-se-9p11 | Intuition\n\n1. We need to find an assignment where the maximum number of workers can be assigned tasks, potentially using pills to boost their strength if nece | keepcalmhgkm | NORMAL | 2024-04-08T12:58:29.535441+00:00 | 2024-04-08T12:58:29.535470+00:00 | 130 | false | # Intuition\n\n1. We need to find an assignment where the maximum number of workers can be assigned tasks, potentially using pills to boost their strength if necessary.\n2. A greedy approach might not be optimal as stronger workers might be better suited for higher-strength tasks even after using pills on weaker ones.\... | 1 | 0 | ['Binary Search', 'Binary Search Tree', 'Ordered Map', 'Ordered Set', 'C++'] | 0 |
maximum-number-of-tasks-you-can-assign | JAVA Simple TreeMap and binarySerch Solution | java-simple-treemap-and-binaryserch-solu-oox0 | ```\nclass Solution {\n \n public int maxTaskAssign(int[] tasks, int[] workers, int pills, int strength) { \n Arrays.sort(tasks);\n Arrays | newton3010 | NORMAL | 2022-02-26T07:46:15.273882+00:00 | 2022-02-26T07:46:15.273912+00:00 | 587 | false | ```\nclass Solution {\n \n public int maxTaskAssign(int[] tasks, int[] workers, int pills, int strength) { \n Arrays.sort(tasks);\n Arrays.sort(workers);\n \n int st = 0;\n int end = Math.min(tasks.length, workers.length)-1;\n int ans =0;\n while(st<=end){\n ... | 1 | 0 | ['Tree', 'Java'] | 0 |
maximum-number-of-tasks-you-can-assign | [JavaScript | JS] BinarySearch | javascript-js-binarysearch-by-wwwap-tn62 | \n\njs\n/**\n * @param {number[]} tasks\n * @param {number[]} workers\n * @param {number} pills\n * @param {number} strength\n * @return {number}\n */\nconst ma | wwwap | NORMAL | 2021-11-30T03:31:17.880530+00:00 | 2021-11-30T03:31:17.880576+00:00 | 221 | false | \n\n```js\n/**\n * @param {number[]} tasks\n * @param {number[]} workers\n * @param {number} pills\n * @param {number} strength\n * @return {number}\n */\nconst maxTaskAssign = function(tasks, workers, pills, strength) {\n tasks.sort((a, b) => a - b)\n workers.sort((a, b) => b - a)\n const m = tasks.length, n = work... | 1 | 0 | ['Binary Tree', 'JavaScript'] | 0 |
maximum-number-of-tasks-you-can-assign | Simple explaination using binary search + greedy | simple-explaination-using-binary-search-5dpf2 | \nclass Solution {\npublic:\n bool can_do_m_tasks(int m,vector<int> &tasks,vector<int> &workers,int pills,int strength)\n {\n multiset<int> ms;\n | deepak_ky | NORMAL | 2021-11-29T14:15:06.135741+00:00 | 2021-11-29T14:15:06.135773+00:00 | 377 | false | ```\nclass Solution {\npublic:\n bool can_do_m_tasks(int m,vector<int> &tasks,vector<int> &workers,int pills,int strength)\n {\n multiset<int> ms;\n for(auto x : workers)\n {\n ms.insert(x);\n }\n \n //I I want to check If I complete m tasks, \n //I will... | 1 | 1 | ['Greedy', 'C', 'Binary Tree'] | 0 |
maximum-number-of-tasks-you-can-assign | JAVA | Greedy | O(n*logn*logn) | java-greedy-onlognlogn-by-dakshbhabra-e1zv | \n\nclass Solution {\n public int maxTaskAssign(int[] t, int[] w, int p, int s) {\n int n = w.length;\n int m = t.length;\n Arrays.sort( | dakshbhabra | NORMAL | 2021-11-28T18:56:36.359356+00:00 | 2021-11-28T18:57:20.824723+00:00 | 558 | false | \n```\nclass Solution {\n public int maxTaskAssign(int[] t, int[] w, int p, int s) {\n int n = w.length;\n int m = t.length;\n Arrays.sort(t);\n \n int lo = 1, hi = Math.min(n, m); // hi = Math.min(n, m), since max tasks you can assign is the minimum of tasks and workers\n ... | 1 | 0 | ['Greedy', 'Tree', 'Java'] | 1 |
maximum-number-of-tasks-you-can-assign | [C++] Binary Search, O(NlgN) using std::list | c-binary-search-onlgn-using-stdlist-by-s-vxo7 | O(NlgN) using std::list\n\nc++\nclass Solution {\npublic:\n int maxTaskAssign(vector<int>& tasks, vector<int>& workers, int pills, int strength) {\n s | slo | NORMAL | 2021-11-14T10:08:46.208558+00:00 | 2021-11-24T17:49:05.843093+00:00 | 276 | false | # O(NlgN) using std::list\n\n```c++\nclass Solution {\npublic:\n int maxTaskAssign(vector<int>& tasks, vector<int>& workers, int pills, int strength) {\n sort(begin(tasks), end(tasks));\n sort(begin(workers), end(workers));\n auto check = [&](int n) {\n list<int> S(end(workers) - n, e... | 1 | 0 | [] | 1 |
maximum-number-of-tasks-you-can-assign | C++ Why is this TLE? Thanks | c-why-is-this-tle-thanks-by-robbinb1993-qugs | Came up with this binary search solution and greedy approach but kept hitting time limit during contest. Complexity is O(N (log N)^2). What is wrong with it? Th | robbinb1993 | NORMAL | 2021-11-13T16:22:25.856315+00:00 | 2021-11-13T16:39:40.545142+00:00 | 340 | false | Came up with this binary search solution and greedy approach but kept hitting time limit during contest. Complexity is O(N (log N)^2). What is wrong with it? Thanks.\n\n```\nclass Solution {\npublic:\n bool possible(const int M, vector<int>& tasks, vector<int>& workers, int pills, int strength) {\n \n ... | 1 | 0 | [] | 5 |
maximum-number-of-tasks-you-can-assign | cpp greedy using bserach | cpp-greedy-using-bserach-by-hareeshghk-5e39 | IntuitionApproachComplexity
Time complexity:
O(log N * (M+N) * log M)
Space complexity:
O(M) for multisetCode | hareeshghk | NORMAL | 2025-03-29T19:09:34.421507+00:00 | 2025-03-29T19:09:34.421507+00:00 | 39 | 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)$$ -->
O(log N * (M+N) * log M)
- Space complexity:
<!-- Add your space complexity here, e.g... | 0 | 0 | ['C++'] | 1 |
maximum-number-of-tasks-you-can-assign | Python Hard | python-hard-by-lucasschnee-no5l | null | lucasschnee | NORMAL | 2025-01-17T19:51:26.928932+00:00 | 2025-01-17T19:51:26.928932+00:00 | 7 | false |
```python3 []from sortedcontainers import SortedList
class Solution:
def maxTaskAssign(self, tasks: List[int], workers: List[int], pills: int, strength: int) -> int:
'''
we want to maximize the number of tasks selected
we need to do this in nlogn or better
binary search on whether... | 0 | 0 | ['Python3'] | 0 |
maximum-number-of-tasks-you-can-assign | 2071. Maximum Number of Tasks You Can Assign | 2071-maximum-number-of-tasks-you-can-ass-4yxm | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | G8xd0QPqTy | NORMAL | 2025-01-17T15:58:48.978951+00:00 | 2025-01-17T15:58:48.978951+00:00 | 16 | 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 |
maximum-number-of-tasks-you-can-assign | maximum-number-of-tasks-you-can-assign- TS Solution | maximum-number-of-tasks-you-can-assign-t-rr14 | \n# Code\ntypescript []\n/**\n * Maximize the number of tasks assigned to workers given their strength and the option to use pills.\n *\n * @param {number[]} ta | himashusharma | NORMAL | 2024-11-12T07:06:56.499993+00:00 | 2024-11-12T07:06:56.500040+00:00 | 13 | false | \n# Code\n```typescript []\n/**\n * Maximize the number of tasks assigned to workers given their strength and the option to use pills.\n *\n * @param {number[]} tasks - An array of tasks where each task has a specific strength requirement.\n * @param {number[]} workers - An array of workers where each worker has a spec... | 0 | 0 | ['Array', 'Binary Search', 'Greedy', 'Queue', 'Sorting', 'Monotonic Queue', 'TypeScript', 'JavaScript'] | 0 |
maximum-number-of-tasks-you-can-assign | Golang | 26ms | Binary Search | Dequeue | golang-26ms-binary-search-dequeue-by-har-ly45 | golang []\npackage main\n\nimport (\n\t"sort"\n)\n\nfunc maxTaskAssign(tasks []int, workers []int, pills int, strength int) int {\n\tsort.Ints(tasks)\n\tsort.In | harshawasthi90 | NORMAL | 2024-11-07T20:20:38.115715+00:00 | 2024-11-12T07:32:04.500123+00:00 | 15 | false | ```golang []\npackage main\n\nimport (\n\t"sort"\n)\n\nfunc maxTaskAssign(tasks []int, workers []int, pills int, strength int) int {\n\tsort.Ints(tasks)\n\tsort.Ints(workers)\n\n\tl := 0\n\tr := min(len(tasks), len(workers))\n\n\tfor l < r {\n\t\tm := (l + r + 1) / 2\n\t\tif ok(tasks[:m], workers[len(workers)-m:], pill... | 0 | 0 | ['Go'] | 0 |
maximum-number-of-tasks-you-can-assign | Beautiful question || C++ || Binary search || Pure greedy won't work | beautiful-question-c-binary-search-pure-z89f3 | 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 | garvit_17 | NORMAL | 2024-11-05T22:41:56.845227+00:00 | 2024-11-05T22:41:56.845258+00:00 | 34 | 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 |
maximum-number-of-tasks-you-can-assign | Python 3: TC O(min(W,T)*log^2(min(W,T)), SC O(min(W,T)): Optimized Time Complexity | python-3-tc-ominwtlog2minwt-sc-ominwt-op-hdi0 | Intuition\n\nThis solution is similar I think to the fastest ones, but offers better asymptotic complexity. Most solutions pop an intermediate index from a list | biggestchungus | NORMAL | 2024-08-26T10:03:01.686225+00:00 | 2024-08-26T10:03:01.686250+00:00 | 7 | false | # Intuition\n\nThis solution is similar I think to the fastest ones, but offers better asymptotic complexity. Most solutions pop an intermediate index from a list which takes `O(k)` time where `k <= min(W, T)`. There may be many pop operations so you wind up with `O(k**2)` time in binary search.\n\n**I found this probl... | 0 | 0 | ['Python3'] | 0 |
maximum-number-of-tasks-you-can-assign | Binary search on answer + Greedy + Monotonic queue | Java faster than 100% | binary-search-on-answer-greedy-monotonic-1n4f | 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 | zephyryau | NORMAL | 2024-08-13T01:22:45.007008+00:00 | 2024-08-13T01:22:45.007042+00:00 | 67 | 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:\nO(nlogn + mlogm)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution {\n int[] deque;\n\n public int maxTaskAssign(in... | 0 | 0 | ['Java'] | 0 |
maximum-number-of-tasks-you-can-assign | This is an addition to a good solution | this-is-an-addition-to-a-good-solution-b-ku2z | Intuition\nPlease read this solution first, as I think it is pretty intuitive: https://leetcode.com/problems/maximum-number-of-tasks-you-can-assign/solutions/15 | Fustigate | NORMAL | 2024-06-28T13:22:34.311319+00:00 | 2024-06-28T13:22:34.311349+00:00 | 32 | false | # Intuition\nPlease read this solution first, as I think it is pretty intuitive: https://leetcode.com/problems/maximum-number-of-tasks-you-can-assign/solutions/1575980/python-binary-search-check-answer-greedily/\n\nAfter that, use the code I provided below, which is a more efficient implementation of the solution at th... | 0 | 0 | ['Binary Search', 'Python3'] | 0 |
maximum-number-of-tasks-you-can-assign | JS | Clean Code Binary Search + Queue | js-clean-code-binary-search-queue-by-nan-p9tp | Code\n\n/**\n * @param {number[]} tasks\n * @param {number[]} workers\n * @param {number} pills\n * @param {number} strength\n * @return {number}\n */\nvar maxT | nanlyn | NORMAL | 2024-06-03T18:16:18.513956+00:00 | 2024-06-03T18:16:18.513975+00:00 | 10 | false | # Code\n```\n/**\n * @param {number[]} tasks\n * @param {number[]} workers\n * @param {number} pills\n * @param {number} strength\n * @return {number}\n */\nvar maxTaskAssign = function (tasks, workers, pills, strength) {\n tasks.sort((a, b) => a - b);\n workers.sort((a, b) => b - a);\n\n const canCompleted = ... | 0 | 0 | ['JavaScript'] | 0 |
maximum-number-of-tasks-you-can-assign | EASY SOLUTION || CLEAN CODE | easy-solution-clean-code-by-udittyagi07-yu6h | \n# Code\n\nclass Solution {\npublic:\n bool check(vector<int>& tasks, vector<int>& workers, int pills, int strength,int index)\n {\n multiset<int> | udittyagi07 | NORMAL | 2024-05-07T06:54:20.039118+00:00 | 2024-05-07T06:54:20.039148+00:00 | 84 | false | \n# Code\n```\nclass Solution {\npublic:\n bool check(vector<int>& tasks, vector<int>& workers, int pills, int strength,int index)\n {\n multiset<int> st;\n for(auto it:workers)\n {\n st.insert(it);\n }\n for(int i=index-1;i>=0;i--)\n {\n auto it=st.... | 0 | 0 | ['C++'] | 0 |
maximum-number-of-tasks-you-can-assign | C++ | c-by-user5976fh-iktq | \nclass Solution {\npublic:\n int maxTaskAssign(vector<int>& tasks, vector<int>& workers, int pills, int strength) {\n int ans = 0, l = 0, r = tasks.s | user5976fh | NORMAL | 2024-04-03T18:13:29.133995+00:00 | 2024-04-03T18:13:29.134030+00:00 | 0 | false | ```\nclass Solution {\npublic:\n int maxTaskAssign(vector<int>& tasks, vector<int>& workers, int pills, int strength) {\n int ans = 0, l = 0, r = tasks.size();\n sort(tasks.begin(), tasks.end());\n while (l <= r){\n int m = (l + r) / 2;\n bool valid = true;\n int... | 0 | 0 | [] | 0 |
maximum-number-of-tasks-you-can-assign | Binary Search + Deque | binary-search-deque-by-kaicool9789-z8o3 | 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 | kaicool9789 | NORMAL | 2024-03-15T06:48:54.723879+00:00 | 2024-03-15T06:48:54.723914+00:00 | 47 | 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 | ['Binary Search', 'C++'] | 0 |
maximum-number-of-tasks-you-can-assign | 👏👏👏👏👏Runtime 840 ms Beats 50.00% of users with Go | runtime-840-ms-beats-5000-of-users-with-7516n | Code\n\nfunc maxTaskAssign(tasks []int, workers []int, pills int, strength int) int {\n n := len(tasks)\n\tm := len(workers)\n\n\t// Sorting the tasks and wo | pvt2024 | NORMAL | 2024-02-24T03:30:11.236327+00:00 | 2024-02-24T03:30:11.236346+00:00 | 12 | false | # Code\n```\nfunc maxTaskAssign(tasks []int, workers []int, pills int, strength int) int {\n n := len(tasks)\n\tm := len(workers)\n\n\t// Sorting the tasks and workers in increasing order\n\tsort.Ints(tasks)\n\tsort.Ints(workers)\n\tlo := 0\n\thi := min(m, n)\n\tans := -1\n\n\tfor lo <= hi {\n\t\tmid := lo + (hi-lo)... | 0 | 0 | ['Go'] | 0 |
maximum-number-of-tasks-you-can-assign | Greedy+Binary search + Deque | greedybinary-search-deque-by-hidanie-xpx1 | Intuition\n Describe your first thoughts on how to solve this problem. \nThere are two stages:\nA. A binary scan should be used to check the amount of work that | hidanie | NORMAL | 2023-12-28T18:07:40.560013+00:00 | 2023-12-28T18:07:40.560031+00:00 | 172 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThere are two stages:\nA. A binary scan should be used to check the amount of work that can be done.\nB. To check if it is possible to do a job of size n, you have to check for each worker if he can do it without a pill and otherwise look... | 0 | 0 | ['Java'] | 0 |
maximum-number-of-tasks-you-can-assign | Python 100% | python-100-by-dkoshman-wnpp | Code\n\nimport bisect\nimport collections\n\ndef binsearch(low, high, do_not_search_less_than):\n while high - low > 1:\n mid = (low + high) // 2\n | dkoshman | NORMAL | 2023-12-26T11:28:25.042057+00:00 | 2023-12-26T11:28:25.042097+00:00 | 26 | false | # Code\n```\nimport bisect\nimport collections\n\ndef binsearch(low, high, do_not_search_less_than):\n while high - low > 1:\n mid = (low + high) // 2\n if do_not_search_less_than(mid):\n low = mid\n else:\n high = mid\n return low\n\nclass TaskAssigner:\n def __init_... | 0 | 0 | ['Python3'] | 0 |
maximum-number-of-tasks-you-can-assign | MaxTask || Binary Search + Greedy || Java || TreeMap || MultiSet || Predicate Function | maxtask-binary-search-greedy-java-treema-0whe | \nclass Solution {\n public int maxTaskAssign(int[] tasks, int[] workers, int pills, int strength) {\n int ans = 0;\n int low = 0;\n int | jyothi_prakash | NORMAL | 2023-12-03T11:41:33.597188+00:00 | 2023-12-03T11:41:33.597244+00:00 | 2 | false | ```\nclass Solution {\n public int maxTaskAssign(int[] tasks, int[] workers, int pills, int strength) {\n int ans = 0;\n int low = 0;\n int high = tasks.length;\n \n Arrays.sort(workers);\n Arrays.sort(tasks);\n \n while(low<=high){\n int mid = low+(... | 0 | 0 | [] | 0 |
maximum-number-of-tasks-you-can-assign | Binary Search + Linear Greedy in Python3 | binary-search-linear-greedy-in-python3-b-a0uf | Intuition\n Describe your first thoughts on how to solve this problem. \nThis solution employs binary search to find the largest $k$ so that $k$ tasks can be co | metaphysicalist | NORMAL | 2023-11-28T14:18:10.478729+00:00 | 2023-11-28T14:18:10.478768+00:00 | 193 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis solution employs binary search to find the largest $k$ so that $k$ tasks can be completed by $k$ workers. To check if $k$ tasks can be completed, this solution performs an efficient linear time greedy algorithm by using a monotonic q... | 0 | 0 | ['Binary Search', 'Monotonic Queue', 'Python3'] | 0 |
maximum-number-of-tasks-you-can-assign | Binary Search + Greedy | binary-search-greedy-by-tanmaygoyal_13-j6xm | Intuition\nTo check how to solve the easiest m tasks using the strongest m workers.\n\n# Approach\nSort the task and worker strenght vectors in increasing order | tanmaygoyal_13 | NORMAL | 2023-09-08T16:06:06.874252+00:00 | 2023-09-08T16:06:06.874271+00:00 | 101 | false | # Intuition\nTo check how to solve the easiest m tasks using the strongest m workers.\n\n# Approach\nSort the task and worker strenght vectors in increasing order. Then, binary search over the number of tasks that can be completed using the provided workers and the pills. \n\nFor each of the chosen m easiest tasks, mak... | 0 | 0 | ['C++'] | 0 |
maximum-number-of-tasks-you-can-assign | Sorting and Searching Solution based on given hint | sorting-and-searching-solution-based-on-jwqn2 | Code\n\nclass Solution {\npublic:\n int maxTaskAssign(vector<int>& task, vector<int>& workers, int pills, int strength) {\n int t=task.size(),w=worker | Putul77 | NORMAL | 2023-07-28T15:09:36.862002+00:00 | 2023-07-28T15:09:51.370273+00:00 | 111 | false | # Code\n```\nclass Solution {\npublic:\n int maxTaskAssign(vector<int>& task, vector<int>& workers, int pills, int strength) {\n int t=task.size(),w=workers.size();\n sort(task.begin(),task.end());\n int ans=0;\n sort(workers.begin(),workers.end());\n int start=0,end=min(t,w)-1;\n\... | 0 | 0 | ['Binary Search', 'Sorting', 'C++'] | 0 |
maximum-number-of-tasks-you-can-assign | Python 3 (No binary search) Faster than 100% | python-3-no-binary-search-faster-than-10-p5rp | \n# Intuition\n Describe your first thoughts on how to solve this problem. \nThe inituition: Starts with realizing that you can complete at most k tasks. \nWher | xxx1xxx1 | NORMAL | 2023-07-27T20:54:45.745472+00:00 | 2023-07-27T20:54:45.745490+00:00 | 53 | false | \n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe inituition: Starts with realizing that you can complete at most k tasks. \nWhere `k = mi... | 0 | 0 | ['Stack', 'Monotonic Stack', 'Python3'] | 1 |
maximum-number-of-tasks-you-can-assign | Binary Search || Multi Set || C++ | binary-search-multi-set-c-by-scrapernerd-j6np | 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 | ScraperNerd | NORMAL | 2023-07-25T18:13:16.688593+00:00 | 2023-07-25T18:13:16.688611+00:00 | 37 | 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 |
maximum-number-of-tasks-you-can-assign | Easy, Simple and Fastest way in C++ | easy-simple-and-fastest-way-in-c-by-ashu-zipx | Complexity\n- Time complexity:\nO(wLen*tLen)\n\n- Space complexity:\nO(wLen)\n\n# Code\n\nclass Solution {\n bool checkTask(vector<int>& tasks, vector<int>& | ashujain | NORMAL | 2023-07-01T15:55:39.302657+00:00 | 2023-07-01T15:55:39.302675+00:00 | 74 | false | # Complexity\n- Time complexity:\nO(wLen*tLen)\n\n- Space complexity:\nO(wLen)\n\n# Code\n```\nclass Solution {\n bool checkTask(vector<int>& tasks, vector<int>& workers, int pills, int strength, int mid) {\n multiset<int> mSet(workers.begin(), workers.end());\n\n for(int i = mid-1; i>=0; i--) {\n ... | 0 | 0 | ['C++'] | 0 |
maximum-number-of-tasks-you-can-assign | BINARY SEARCH SOLUTION | binary-search-solution-by-parwez0786-4s7d | 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 | parwez0786 | NORMAL | 2023-06-21T13:22:33.986602+00:00 | 2023-06-21T13:22:33.986621+00:00 | 43 | 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 |
maximum-number-of-tasks-you-can-assign | Apply Binary Search on Answer!!!✌️🔥🔥🔥 | apply-binary-search-on-answer-by-yashpad-sbwr | \n\n# Code\n\nclass Solution {\npublic:\n bool f(int mid,vector<int>& tasks, vector<int>& workers,int pills,int strength){\n multiset<int>ms;\n fo | yashpadiyar4 | NORMAL | 2023-06-01T13:32:31.946478+00:00 | 2023-06-01T13:32:31.946547+00:00 | 118 | false | \n\n# Code\n```\nclass Solution {\npublic:\n bool f(int mid,vector<int>& tasks, vector<int>& workers,int pills,int strength){\n multiset<int>ms;\n for(int i=workers.size()-1;i>=0;i--){\n ms.insert(workers[i]);\n }\n for(int i=mid-1;i>=0;i--){\n auto it=ms.end();\n ... | 0 | 0 | ['Binary Search', 'Greedy', 'Sorting', 'C++'] | 0 |
maximum-number-of-tasks-you-can-assign | Easy C++ Code | easy-c-code-by-rishabhjain26012002-66e3 | 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 | rishabhjain26012002 | NORMAL | 2023-05-26T06:13:55.012465+00:00 | 2023-05-26T06:13:55.012505+00:00 | 79 | 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 |
maximum-number-of-tasks-you-can-assign | Python (Simple Binary Search) | python-simple-binary-search-by-rnotappl-0bul | 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 | rnotappl | NORMAL | 2023-04-18T21:43:46.963820+00:00 | 2023-04-18T21:43:46.963850+00:00 | 60 | 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 | ['Python3'] | 0 |
maximum-number-of-tasks-you-can-assign | C++ | c-by-tinachien-e2ru | \nclass Solution {\n bool check(int k, const vector<int>& tasks, const vector<int>& workers, int pills, int strength){\n int idxW = 0 ;\n int f | TinaChien | NORMAL | 2023-04-09T02:05:53.165761+00:00 | 2023-04-09T02:05:53.165801+00:00 | 20 | false | ```\nclass Solution {\n bool check(int k, const vector<int>& tasks, const vector<int>& workers, int pills, int strength){\n int idxW = 0 ;\n int finish = 0 ;\n multiset<int>Set(workers.end() - k, workers.end()) ;\n\n for(int i = k-1; i >= 0; i--){ \n if(*Set.rbegin() >= tasks[i... | 0 | 0 | ['Sorting', 'Binary Tree'] | 0 |
maximum-number-of-tasks-you-can-assign | Just a runnable solution | just-a-runnable-solution-by-ssrlive-jehc | Code\n\nimpl Solution {\n pub fn max_task_assign(tasks: Vec<i32>, workers: Vec<i32>, pills: i32, strength: i32) -> i32 {\n use std::collections::VecDe | ssrlive | NORMAL | 2023-03-08T10:22:45.432423+00:00 | 2023-03-08T10:22:45.432460+00:00 | 21 | false | # Code\n```\nimpl Solution {\n pub fn max_task_assign(tasks: Vec<i32>, workers: Vec<i32>, pills: i32, strength: i32) -> i32 {\n use std::collections::VecDeque;\n\n fn check(tasks: &[i32], workers: &[i32], pills: i32, strength: i32, k: usize) -> bool {\n let mut pills = pills;\n if... | 0 | 0 | ['Rust'] | 0 |
maximum-number-of-tasks-you-can-assign | binary search and deque | binary-search-and-deque-by-jingnan4-n99w | 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 | jingnan4 | NORMAL | 2023-01-31T01:22:52.181515+00:00 | 2023-01-31T01:25:14.397605+00:00 | 280 | 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)$$ -->\nnlogn\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)... | 0 | 0 | ['Java'] | 0 |
maximum-number-of-tasks-you-can-assign | [JavaScript/C++] BinarySearch, Queue | javascriptc-binarysearch-queue-by-tmohan-gndn | Greedy Approach\n- Pills are precious, so avoid using them as much as possible\n- In case we are forced to use pills, give pill to lower potential worker who ca | tmohan | NORMAL | 2023-01-10T06:24:35.230894+00:00 | 2023-01-10T06:38:05.878089+00:00 | 176 | false | # Greedy Approach\n- Pills are precious, so avoid using them as much as possible\n- In case we are forced to use pills, give pill to lower potential worker who can complete the task, i.e., **workerEngergy < task --whereas-- workerEnergy + strengthFromOnePill >= task**\n- deque store the workers in decreasing order of t... | 0 | 0 | ['Binary Search', 'Queue', 'Sorting', 'C++', 'JavaScript'] | 0 |
maximum-number-of-tasks-you-can-assign | Python SortedList OR bisect | python-sortedlist-or-bisect-by-panoslin-knil | There are 2 ways of doing binary search for this problem using Python\nLet N, M be the legth of tasks and worker respectively.\n1. SortedList - TC: logN * N * l | panoslin | NORMAL | 2022-12-01T08:18:42.768050+00:00 | 2022-12-01T08:52:01.481664+00:00 | 75 | false | There are 2 ways of doing binary search for this problem using Python\nLet N, M be the legth of tasks and worker respectively.\n1. SortedList - TC: `logN * N * logM * logM`\n2. bisect - TC: `logN * N * logM * M`\n\nHere\n` logN` is from the outest binary search\n`N` is from the for loop in ch... | 0 | 0 | ['Binary Tree'] | 0 |
maximum-number-of-tasks-you-can-assign | [Python] Binary search and greedy check | python-binary-search-and-greedy-check-by-1phg | \nfrom bisect import bisect_left\n\nclass Solution:\n def maxTaskAssign(self, tasks: List[int], workers: List[int], pills: int, strength: int) -> int:\n | cava | NORMAL | 2022-10-13T02:22:06.395856+00:00 | 2022-10-13T02:22:06.395916+00:00 | 67 | false | ```\nfrom bisect import bisect_left\n\nclass Solution:\n def maxTaskAssign(self, tasks: List[int], workers: List[int], pills: int, strength: int) -> int:\n tasks.sort()\n workers.sort()\n ans, lo, hi = 0, 1, min(len(workers), len(tasks))\n while lo <= hi:\n mid = (lo + hi) // 2... | 0 | 0 | [] | 0 |
maximum-number-of-tasks-you-can-assign | Exlplanation why BinearySearch works & Greedy does NOT | exlplanation-why-binearysearch-works-gre-bgp2 | \n def maxTaskAssign(self, tasks: List[int], workers: List[int], pills: int, strength: int) -> int:\n \n maxTasks = min(len(tasks), len(workers | sarthakBhandari | NORMAL | 2022-09-15T20:38:23.835873+00:00 | 2022-09-15T20:39:58.584084+00:00 | 148 | false | ```\n def maxTaskAssign(self, tasks: List[int], workers: List[int], pills: int, strength: int) -> int:\n \n maxTasks = min(len(tasks), len(workers))\n workers.sort()\n tasks.sort()\n #u can try a greedy approach, I spent days and it got better but it didnt work 100% time\n #... | 0 | 0 | ['Greedy', 'Binary Tree', 'Python'] | 0 |
maximum-number-of-tasks-you-can-assign | [C++] || with komments | c-with-komments-by-gurbeege-39u6 | \nint maxTaskAssign(vector<int>& tasks, vector<int>& ws, int pills, int strength) {\n sort(tasks.begin(), tasks.end());\n sort(ws.begin(), ws.end( | Gurbeege | NORMAL | 2022-09-12T21:31:19.460111+00:00 | 2022-09-12T21:31:19.460156+00:00 | 82 | false | ```\nint maxTaskAssign(vector<int>& tasks, vector<int>& ws, int pills, int strength) {\n sort(tasks.begin(), tasks.end());\n sort(ws.begin(), ws.end());\n \n \n int l = 0, r = min(tasks.size(), ws.size());\n while(l<r){\n int m = (l+r+1)/2, need = 0;\n \n ... | 0 | 0 | [] | 0 |
maximum-number-of-tasks-you-can-assign | Greedy + Binary Search | greedy-binary-search-by-aknov711-wddn | \nclass Solution {\npublic:\n int maxTaskAssign(vector<int>& tasks, vector<int>& workers, int pills, int strength) {\n // is it optimal to give all pi | aknov711 | NORMAL | 2022-08-23T14:22:10.721159+00:00 | 2022-08-23T14:22:10.721200+00:00 | 114 | false | ```\nclass Solution {\npublic:\n int maxTaskAssign(vector<int>& tasks, vector<int>& workers, int pills, int strength) {\n // is it optimal to give all pills to the \n // people with highest stength ??? \n \n // No \n \n // Observation : If I give a pill to ith person, then \... | 0 | 0 | [] | 0 |
maximum-number-of-tasks-you-can-assign | [C++] Multiset Greedy Binary Search | c-multiset-greedy-binary-search-by-caoba-v6mh | My idea is simple. We have 3 observations:\n1. If we can do n tasks then we can do n-1 tasks => We use binary search to find result.\n2. If we do n tasks we wil | caobaohoang03 | NORMAL | 2022-08-12T11:26:32.623728+00:00 | 2022-08-12T11:27:57.437498+00:00 | 123 | false | My idea is simple. We have 3 observations:\n1. If we can do n tasks then we can do n-1 tasks => We use binary search to find result.\n2. If we do n tasks we will chooses n smallest tasks and n highest workers (greedy)\n3. For one worker we will assign it to nearest task. If no nearest task smaller than worker, we will ... | 0 | 0 | ['Greedy', 'Binary Tree'] | 0 |
maximum-number-of-tasks-you-can-assign | python3 O(nlogn) bs+queue | python3-onlogn-bsqueue-by-wenzhenl-mt0n | Note the check takes O(n), starting from the hardest task, if the strongest worker can take it, then let the worker do it, otherwise find the weakest worker who | wenzhenl | NORMAL | 2022-08-06T00:25:45.373408+00:00 | 2022-08-06T00:25:45.373449+00:00 | 88 | false | Note the `check` takes O(n), starting from the hardest task, if the strongest worker can take it, then let the worker do it, otherwise find the weakest worker who can do it with the pill. So we can maintain a queue which contains all workers who can do it with the pill. If the strongest one (`queue[0]`) can do it witho... | 0 | 0 | [] | 0 |
maximum-number-of-tasks-you-can-assign | Optimal Solution, no Binary Seach O(nlogn) | optimal-solution-no-binary-seach-onlogn-2f1ff | Sort both tasks and workers in decreasing order.\\nLet used denotes a set of workers using pills.\n If the hardest task is smaller than the strongest worker, ad | horizon1006 | NORMAL | 2022-07-28T19:15:35.383375+00:00 | 2022-07-28T20:03:15.424774+00:00 | 129 | false | Sort both tasks and workers in decreasing order.\\\nLet `used` denotes a set of workers using pills.\n* If the hardest task is smaller than the strongest worker, add `1` to the answer, remove both of the task and the worker \n* Otherwise, a worker must takes the pills to be able to do the task. As one must be chosen, w... | 0 | 0 | [] | 0 |
maximum-number-of-tasks-you-can-assign | How can this be wrong ??? | how-can-this-be-wrong-by-kumarambuj-hisx | \nclass Solution:\n def maxTaskAssign(self, t: List[int], workers: List[int], pills: int, s: int) -> int:\n \n t.sort()\n workers.sort() | kumarambuj | NORMAL | 2022-06-16T06:42:49.686881+00:00 | 2022-06-16T06:42:49.686932+00:00 | 157 | false | ```\nclass Solution:\n def maxTaskAssign(self, t: List[int], workers: List[int], pills: int, s: int) -> int:\n \n t.sort()\n workers.sort()\n \n A=t.copy()\n B=workers.copy()\n p=pills\n ans=0\n a=False\n b=False\n while(len(A)>0 and len(B)... | 0 | 0 | ['Greedy', 'Python'] | 1 |
maximum-number-of-tasks-you-can-assign | Java | Binary Search and Greedy | LinkedHashset | java-binary-search-and-greedy-linkedhash-qvte | \n/*\nThe binary search approach is not very obvious here.\n\nThe idea is to pick k easiest tasks, and k strongest workers, and see if we can assign those tasks | wilson_chuks | NORMAL | 2022-04-09T06:53:19.563094+00:00 | 2022-04-09T06:53:19.563142+00:00 | 306 | false | ```\n/*\nThe binary search approach is not very obvious here.\n\nThe idea is to pick k easiest tasks, and k strongest workers, and see if we can assign those tasks.\n\nWith this set of k strongest workers and k easiest tasks, we:\n\nProcess tasks from hardest to easiest\nCheck if the strongest worker can do the hardest... | 0 | 0 | [] | 0 |
maximum-number-of-tasks-you-can-assign | C++ 96% (Time and Mem) Iterative approach with Priority Queue, commented | c-96-time-and-mem-iterative-approach-wit-5jpv | int maxTaskAssign(vector& tasks, vector& workers, int pills, int strength) {\n \n // Sort in descending order, could sort in ascending. Would just | Tkyl | NORMAL | 2022-03-14T18:59:16.078764+00:00 | 2022-03-14T18:59:16.078794+00:00 | 499 | false | int maxTaskAssign(vector<int>& tasks, vector<int>& workers, int pills, int strength) {\n \n // Sort in descending order, could sort in ascending. Would just need to change loop iteration direction\n sort(tasks.begin(),tasks.end(),[](int lhs, int rhs) {return lhs > rhs;});\n sort(workers.begi... | 0 | 0 | ['C', 'Heap (Priority Queue)'] | 0 |
maximum-number-of-tasks-you-can-assign | Python | greedy + binary search using monotonic que | O(nlogn) | python-greedy-binary-search-using-monoto-jt3r | \nfrom collections import deque\nclass Solution:\n def maxTaskAssign(self, tasks: List[int], workers: List[int], pills: int, strength: int) -> int:\n | aryonbe | NORMAL | 2022-02-26T11:30:33.737236+00:00 | 2022-04-23T13:24:23.045980+00:00 | 272 | false | ```\nfrom collections import deque\nclass Solution:\n def maxTaskAssign(self, tasks: List[int], workers: List[int], pills: int, strength: int) -> int:\n tasks = sorted(tasks)\n workers = sorted(workers)\n n = len(workers)\n def check(k, pills):\n que = deque()\n idx ... | 0 | 0 | [] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.