Maximum Number of Tasks You Can Assign - Binary Search & Deque [JS]
Description Solution: Binary Search & Deque Binary search for the largest number of tasks that can be completed. How to check whether we can complete k tasks: Try to assign the k weakest tasks to the k strongest workers. Sort tasks in asc order and workers in desc order. Go through the workers from weakest to strongest, Try to assign the easiest task to the worker (without using a pill). If it can be assigned, assign it. (If the easiest task can be done by the worker, that means all following workers will be able to do it without a pill. Therefore, it is optimal for the current task to complete the easiest task) Otherwise, try to do the hardest possible task after using a pill. Keep track of the tasks that are assignable after using a pill in a deque so that we can remove tasks both on the left and right. If we can't assign any task to the worker, return false (we can't complete k tasks). n = number of tasks , m = number of workers Time Complexity: O(n log(n) + m ...