Dsa
Backtracking
Easy
Team Project Assignments
You are organizing a team project and have a list of employees. Each employee can work on multiple projects, but each project can only have a specific number of employees. Your task is to generate all unique assignments of employees to each project while ensuring the project does not exceed the limit on the number of participants.
Input:
- The first line contains an integer N, the number of employees (1 <= N <= 20).
- The second line contains an integer M, the number of projects (1 <= M <= 10).
- The third line contains M integers, where the ith integer represents the maximum number of employees that can work on project i.
- The fourth line contains N space-separated integers representing the employee IDs (unique integers from 1 to N).
Output:
- Print each unique assignment of employees to projects in alphabetical order of employee IDs, each on a new line. Each assignment should be formatted as follows: "Project X: [emp1, emp2, ..., empn]".
Example:
Input:
3
2
2 1
1 2 3
Output:
Project 1: [1, 2]
Project 2: [3]
Key concepts
backtrackingcombinatoricsarrays
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