Question bank › Greedy
Dsa Greedy Easy

Fuel Distribution

You are organizing a road trip and need to plan the fuel distribution across several vehicles. Each vehicle has a maximum fuel capacity, and you need to distribute a limited amount of fuel among them. Each vehicle should receive as much fuel as possible but cannot exceed its capacity. Write a function that takes as input the total amount of fuel available and an array that represents the fuel capacity of each vehicle. Your goal is to maximize the total fuel distributed while respecting each vehicle's capacity. Return the total amount of fuel distributed. Input: - The first line contains an integer `total_fuel` (0 <= total_fuel <= 10000). - The second line contains an integer `n` (1 <= n <= 100), the number of vehicles. - The third line contains `n` space-separated integers (0 <= capacity[i] <= 1000) indicating the fuel capacities of each vehicle. Output: - An integer representing the total amount of fuel distributed. Example: Input: 50 3 20 15 25 Output: 50 In this case, all vehicles can be filled to the maximum capacity without exceeding the total fuel available.

Key concepts

greedyarraycumulative

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.