Solution: Sum of Mutated Array Closest to Target
Explore how to solve the problem of replacing array elements to get the sum closest to a target value. Learn to sort the array, iterate through elements, and calculate an optimal replacement value. Understand the balance between time and space complexity with an O(n log n) solution.
We'll cover the following...
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...