Dsa
Dynamic Programming
Warm-up
Optimal Menu Selection
You are designing a simple menu system for a cafe. You have n menu items, and each can have a certain price. You want to select items such that the total cost does not exceed a budget while maximizing the number of items selected. If items are selected, we cannot select any item that is adjacent to another selected item.
Input Format:
- The first line contains an integer n (1 ≤ n ≤ 50), the number of menu items.
- The second line contains n space-separated integers representing the cost of each menu item.
- The third line contains an integer b (1 ≤ b ≤ 10^4), the budget.
Output Format:
- Print a single integer: the maximum number of items that can be selected without exceeding the budget.
Example:
Input:
4
2 5 3 4
7
Output:
3
Key concepts
dynamic_programminggreedy
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