Question bank › Union Find
Dsa Union Find Easy

Chefs and Recipes

In a restaurant, chefs can collaborate to cook recipes if they share at least one common ingredient. Given a list of recipes and the ingredients they use, your task is to determine how many distinct groups of chefs can collaborate based on shared ingredients. Input: - The first line contains an integer n (1 <= n <= 100), the number of chefs. - The second line contains an integer m (0 <= m <= n*(n-1)/2), the number of recipes. - Each of the next m lines contains a recipe defined by a chef ID followed by a list of integers denoting the ingredients used by that chef. Output: - Print the number of distinct groups of chefs that can collaborate. Example: Input: 3 2 0 1 2 1 2 3 Output: 1

Key concepts

union_findingredientsrecipes

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.