Minimum-Cost Solar Rooftop Allocation
Updated
Problem statement
A colony has n houses. House i requires requirements[i] units of energy. Energy produced by any rooftop enters a shared grid and may satisfy any house.
You may install at most one rooftop on each house:
- A type-one rooftop costs
typeOneCostand produces exactlyrequirements[i]units on housei. - A type-two rooftop costs
typeTwoCostand produces exactly2 * requirements[i]units on housei. - You may also leave a house without a rooftop.
Choose rooftops whose total production is at least the colony's total requirement. Return the minimum possible installation cost.
Function
minimumSolarCost(requirements: long[], typeOneCost: long, typeTwoCost: long) → longExamples
Example 1
requirements = [4,2,1]typeOneCost = 5typeTwoCost = 8return = 8The colony needs 7 units. One type-two rooftop on the house requiring 4 units produces 8 units at cost 8.
Example 2
requirements = [3,3,3]typeOneCost = 4typeTwoCost = 10return = 12Three type-one rooftops produce exactly 9 units for cost 12, which is cheaper than every sufficient combination using type two.
Example 3
requirements = [10,1]typeOneCost = 100typeTwoCost = 3return = 3A type-two rooftop on the first house produces 20 units, enough for the total requirement of 11, at cost 3.
Constraints
1 <= requirements.length <= 1000001 <= requirements[i] <= 10^91 <= typeOneCost, typeTwoCost <= 10^9- The answer fits in a signed 64-bit integer.
More Deloitte Online Assessment questions
- Seventh Nearest PalindromeOA · Seen May 2026
- Minimum Deletions for a Non-PalindromeOA · Seen Jul 2025
- Pair Elements with Even SumsOA · Seen Jul 2025
- Count Divisible PermutationsOA · Seen Jan 2025
- Largest Element in an ArrayOA · Seen Nov 2024
- Install Carbon FiltersOA · Seen Oct 2023
- Longest Substring with Even OccurrencesOA · Seen Oct 2023
- Maximum Sum RectangleOA · Seen Apr 2022
- Annual Bank Balance with Monthly Card FeesOA · Seen Jan 2022
- Count Battleships by SizeOA · Seen Jan 2022
Similar questions at other companies
- Minimize Maximum Group DifferenceDRW · OADRW interview questions
- Maximize Number of Produced CarsMicrosoft · OAMicrosoft interview questions
- Aggressive CowsPeopleStrong · OAPeopleStrong interview questions
- Spread Cows Across StallsExpedia · OAExpedia interview questions
- Aggressive CowsAmazon · PHONE SCREEN
- Maximize the Minimum Cone DistanceSumo Logic · PHONE SCREEN
- Maximize Fish over Limited HoursByteDance · PHONE SCREENByteDance interview questions
- Find Minimum TimeAlphaSense · OA
- Find Minimum TimeBlackRock · OABlackRock interview questions
- Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions