Question bank › Greedy
Dsa Greedy Medium

Optimal Task Assignment

You have a list of tasks with varying difficulties represented as integers and a list of workers who can each handle a maximum difficulty level. Your goal is to assign each task to a worker such that the total number of completed tasks is maximized. Each worker can only handle one task at a time, and a worker can only take on a task if its difficulty does not exceed their capacity. Input format: - The first line contains an integer W (1 ≤ W ≤ 100), the number of workers. - The second line contains W integers, the maximum difficulties each worker can handle. - The third line contains an integer T (1 ≤ T ≤ 1000), the number of tasks. - The fourth line contains T integers, the difficulties of the tasks. Output format: - Print a single integer: the maximum number of tasks that can be completed. Example: Input: 3 3 5 2 5 1 2 3 4 5 Output: 4

Key concepts

greedysortingpriority

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.