Question bank › Greedy
Dsa Greedy Hard

Balanced Breakfast Plan

You are tasked with preparing a balanced breakfast for a certain number of people. Each person requires a combination of different food items with specific calorie counts. Your goal is to choose food items such that the total calorie count meets the required calorie count exactly. Write a program that reads the number of food items, their calorie counts, and the target calorie count from STDIN, and outputs the minimum number of items needed to reach exactly the target calorie count to STDOUT. Input format: First line contains an integer n (1 <= n <= 1000), number of food items. The second line contains n integers representing the calorie counts of these items (1 <= calorie[i] <= 1000). The third line contains an integer target (1 <= target <= 10000). Output format: A single integer, the minimum number of food items needed to reach the target, or -1 if it cannot be accomplished. Example: Input: 5 250 600 350 200 800 1000 Output: 2

Key concepts

greedycombination

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 Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.