Solution: Sum of Mutated Array Closest to Target
Explore how to determine an integer value that replaces elements greater than it in an array so the total sum approaches a given target. This lesson teaches sorting the array and iterating with a running total to evaluate replacement values, emphasizing minimizing the difference from the target. Understand how to apply these steps and the algorithm's time complexity.
We'll cover the following...
Statement
Given an integer array arr and a target value target, find an integer value such that if all the numbers in arr greater than value are replaced with a value, the sum of the array gets as close as possible to the target.
Choose the smaller value if there’s a tie (two value options are equally close to the targe).
Note: The answer doesn’t have to be a number from the array.
Constraints:
arr.length...