Question bank › Backtracking
Dsa Backtracking Medium

The Ingredient Matchmaker

A chef needs to create a sauce with a total 'intensity' of exactly T. They have N ingredients. Each ingredient has an intensity value and belongs to a 'Group' (integer). To maintain balance, the chef cannot use more than one ingredient from the same Group. Find the minimum number of ingredients needed to reach intensity T. Input: First line contains N and T. Next N lines contain 'intensity group'. If it's impossible, print -1. Example: Input: 4 10 5 1 5 2 10 1 7 3 Output: 1 (Explanation: Can use the ingredient with intensity 10 from Group 1. The combination of two 5s is not allowed because they are both Group 1 and 2? No, wait: 5 1 and 5 2 are allowed. But 10 is fewer ingredients.)

Key concepts

backtrackingsubset sumconflict resolution

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.