Problem · Greedy
Find Minimum Cost
Learn this problemProblem statement
You are given a list of houses, such that A[k] corresponds to the amount of energy needed for house k. You will be installing two types of solar panels:
- Type 1: A solar panel which provides
A[k]amount of power for priceX. - Type 2: A solar panel which provides
2 * A[k]amount of power for priceY.
Your goal is to find the minimum cost such that all houses are provided with at least their required amount of power.
Note: The power distributed from Y is not sequential, as you only focus on providing at least the net amount of energy of all the houses.
Function
findMinimumCost(A: int[], X: int, Y: int) → intExamples
Example 1
A = [4, 3, 5, 2]X = 2Y = 5return = 7Assign solar panel type Y to A[2], which will cover A[1] and A[3], and then assign solar panel type X to A[0].
Thus the minimum cost is 5 + 2 = 7.
Constraints
🥭🥭More Microsoft problems
- Authentication SystemOA · Seen Jul 2026
- Binary String Swap TimeOA · Seen Jul 2026
- Minimum Effort Task ScheduleOA · Seen Jul 2026
- Maximum Pipeline ThroughputOA · Seen Jul 2026
- Maximum Strong Team SubarrayOA · Seen Jul 2026
- Minimum Cost K-Capable ModelsOA · Seen Jul 2026
- Alphabetically Smallest PalindromeOA · Seen Jul 2026
- Maximum Reward PointsOA · Seen Jul 2026