Skip to main content
Back to problems
Leetcode
Medium
Arrays
Binary Search
Greedy
Google
Meta
Maximum Number Of Tasks You Can Assign

Assign the maximum number of tasks to workers using optional pills that boost worker strength.

Acceptance 0%
Problem Statement

You are given a list of task requirements and a list of workers. Each task requires a certain strength to complete, and each worker has a base strength. You may give a limited number of pills, each of which temporarily increases one worker's strength by a fixed amount. A worker can complete at most one task, and each task can be assigned to at most one worker.

Your goal is to determine the maximum number of tasks that can be completed if you assign tasks and pills optimally.

This is a classic feasibility problem: decide whether a given number of tasks can be assigned, then use that check to find the maximum possible count.

Input Format

  • An integer array tasks where tasks[i] is the strength needed for the i-th task.
  • An integer array workers where workers[j] is the base strength of the j-th worker.
  • Two integers pills and strength.

A pill can be used on at most one worker and increases that worker's strength by strength for the assignment.

Output Format

Return the maximum number of tasks that can be completed.

Constraints

  • A worker can complete at most one task.
  • A task can be assigned to at most one worker.
  • At most pills workers may receive a pill.
  • The answer is the largest integer k such that some k tasks can be assigned successfully.
Examples
Sample cases returned by the problem API.

Example 1

Input

tasks = [3,2,1]
workers = [0,3,3]
pills = 1
strength = 1

Output

3

Explanation

Assign task 1 to a worker with strength 3, task 2 to the other strength-3 worker, and use the pill on the worker with strength 0 to finish task 3.

Example 2

Input

tasks = [5,4]
workers = [0,0,0]
pills = 2
strength = 3

Output

0

Explanation

Even with pills, each worker reaches strength 3, which is still not enough for either task.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.