Question bank › Backtracking
Dsa Backtracking Hard

Team Building Assignments

Imagine you are responsible for creating teams for a competition where each team should consist of exactly k members. Given a list of employees' names, your task is to generate all possible unique teams of size k. Each team should be displayed in lexicographically sorted order. If k is larger than the number of employees or is less than 1, return "Invalid team size". Input Format: - The first line contains the integer `n`, the number of employees (1 ≤ n ≤ 15). - The second line contains n space-separated strings representing the names of the employees. - The third line contains the integer `k`, the size of the teams to form (1 ≤ k ≤ n). Output Format: - Print each team on a new line in lexicographically sorted order. If there are no valid teams, print "Invalid team size". Example: Input: 4 Alice Bob Charlie David 2 Output: Alice Bob Alice Charlie Alice David Bob Charlie Bob David Charlie David

Key concepts

backtrackingpermutationsteam formation

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.