Question bank › Dynamic Programming
Dsa Dynamic Programming Easy

Grocery Shopping Cost

You are given an array of prices where prices[i] is the price of the i-th item in a grocery store. You can choose items to buy but you want to maximize your total spending under a budget limit. You need to determine the maximum amount you can spend without exceeding the budget. Input: - The first line contains two integers, n (1 <= n <= 1000) and b (1 <= b <= 10^6), where n is the number of items and b is the budget. - The second line contains n integers representing the prices of the items. Output: - A single integer representing the maximum amount you can spend without exceeding the budget. Example: Input: 5 10 3 2 4 5 1 Output: 10

Key concepts

dynamic_programmingarraycumulative_sum

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.