Question bank › Greedy
Dsa Greedy Easy

Grocery Purchase Optimization

You are given a list of grocery items with their prices and a budget. Your goal is to maximize the number of items you can buy without exceeding the budget. Write a program that reads the budget and a list of prices, and outputs the maximum number of items you can purchase. Input format: - The first line contains an integer B (the budget). - The second line contains an integer N (the number of items). - The third line contains N space-separated integers (the prices of the items). Output format: - A single integer, the maximum number of items you can buy within the budget. Example: Input: 50 5 20 10 30 5 15 Output: 4

Key concepts

greedyarraysorting

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.