Dsa
Binary Search
Medium
Cooking Time Optimization
A chef has many dishes to prepare and each dish takes a certain amount of time to cook. Given an array of integers representing the cooking times for each dish and a total available time t, write a function to find out the maximum number of dishes the chef can cook within the given time.
Input format:
- The first line contains an integer n (1 ≤ n ≤ 10^5), representing the number of dishes.
- The second line contains n space-separated integers, representing the cooking times of each dish.
- The third line contains an integer t (1 ≤ t ≤ 10^9), the total available time.
Output format:
- Output the maximum number of dishes that can be cooked.
Example:
Input:
5
30 10 20 40 50
70
Output:
3
Key concepts
binary_searchprefix_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