Maximum Reservoir Power
Updated
Problem statement
A hydropower plant is connected to n water reservoirs. Opening reservoir i generates capacity[i] units of electricity.
Some pairs of reservoirs conflict and cannot be opened together. The undirected conflict graph is guaranteed to be a forest.
Choose a set of reservoirs with no conflicting pair and return the maximum total electricity they can generate.
The arrays conflictFrom and conflictTo have equal length. Their values are 1-indexed reservoir numbers, and pair j connects conflictFrom[j] with conflictTo[j].
Function
maxReservoirPower(capacity: int[], conflictFrom: int[], conflictTo: int[]) → longExamples
Example 1
capacity = [5,1,4,3]conflictFrom = [1,2,3]conflictTo = [2,3,4]return = 9Open reservoirs 1 and 3 for 5 + 4 = 9 units.
Example 2
capacity = [10,1,1,10]conflictFrom = [1,2,3]conflictTo = [2,3,4]return = 20Reservoirs 1 and 4 are not adjacent, so both can be opened for 20 units.
Example 3
capacity = [8,5,6,4,7,3]conflictFrom = [1,2,4]conflictTo = [2,3,5]return = 24Choose reservoirs 1 and 3 from the first component, reservoir 5 from the second component, and isolated reservoir 6: 8 + 6 + 7 + 3 = 24.
Constraints
1 <= capacity.length <= 10^5.1 <= capacity[i] <= 10^5.conflictFrom.length == conflictTo.length.0 <= conflictFrom.length <= capacity.length - 1.- Every conflict endpoint is between
1andcapacity.length, endpoints in a pair are different, and pairs are unique. - The conflict graph is a forest.
More Wells Fargo Online Assessment questions
- Server Upgrade PlanningOA · Seen Nov 2026
- Student and Course EnrollmentOA · Seen Nov 2026
- Bond Interest Summary Above 3%OA · Seen Oct 2026
- Count Phrases Formed by Anagram ReplacementOA · Seen Oct 2026
- Event Statistics AggregatorOA · Seen Sep 2026
- Ordered Deployment Configuration ValidatorOA · Seen Sep 2026
- Longest Subsequence That Is a SubstringOA · Seen Jul 2026
- Overloaded Game Account InventoriesOA · Seen Jul 2026
- Count Server ReplacementsOA · PHONE SCREEN · Seen Feb 2026
- Minimum Remaining LengthOA · PHONE SCREEN · Seen Feb 2026
Similar questions at other companies
- Minimum Leaf Path Sum over All RootsInfosys · OAInfosys interview questions
- Maximum Strength of Every NeuronMicrosoft · OAMicrosoft interview questions
- Tree Node With Maximum BeautyC3.ai · OAC3.ai interview questions
- Distance Sums to Special Nodes in a Weighted TreeNutanix · ONSITE INTERVIEWNutanix interview questions
- Sum of Weighted Distances in a TreeGoogle · ONSITE INTERVIEWGoogle interview questions
- Base Unit ConversionsAdobe · OAAdobe interview questions
- Part 1: The Narrowest KeyScale AI · OAScale AI interview questions
- Best Sum Downward Tree PathCitadel · OACitadel interview questions
- Longest Transfer Time in a Server TreeRippling · OARippling interview questions
- Longest Alternating a/b Path in a TreeHudson River Trading · OAHudson River Trading interview questions