Skip to main content
All Questions

Compute the minimum total cost to satisfy EV charging demand across slots.

Unlock detailed company stats for this questionUpgrade

You are given n (number of vehicles), t (number of charging slots), mc (maximum capacity of each slot), vehicles[] (charging requirement of each vehicle), costs[] (cost per unit at each slot) and penalty (penalty per unit of unfulfilled energy). The total requirement is the sum of all vehicle requirements and can be distributed among vehicles in any manner. Each slot provides at most mc units. Any unfulfilled energy costs the penalty per unit. A slot can be skipped if its cost per unit is greater than the penalty. Find the minimum total cost.

Example: n = 3, t = 4, mc = 6, vehicles = [5, 7, 3], costs = [10, 4, 8, 20], penalty = 9. Total requirement 15; use the cost-4 slot for 6 units (24) and the cost-8 slot for 6 units (48), leave 3 units to penalty (27), total 99. Slots costing 10 and 20 are skipped because they exceed the penalty.

Community answers

No answers contributed by the community yet.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.