Problem · Greedy

Find Minimum Cost

Learn this problem
MediumMicrosoft logoMicrosoftOA
See Microsoft hiring insights

Problem 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:

  1. Type 1: A solar panel which provides A[k] amount of power for price X.
  2. Type 2: A solar panel which provides 2 * A[k] amount of power for price Y.

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) → int

Examples

Example 1

A = [4, 3, 5, 2]X = 2Y = 5return = 7
Assign 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

drafts saved locally
public int findMinimumCost(int[] A, int X, int Y) {
  // write your code here
}
A[4, 3, 5, 2]
X2
Y5
expected7
checking account