Tap here to switch tabs
Problem
Ask
Submissions

Problem: Sum of Mutated Array Closest to Target

med
30 min
Understand how to determine a mutation value to replace elements in an array greater than this value, so the resulting sum is closest to the target. Learn to apply sorting and binary search to efficiently solve this problem, practicing your skills in problem assessment and algorithm implementation.

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:

  • 11 \leqarr.length 103 \leq 10^3

  • 11 \leqarr[i], target 104\leq 10^4

Tap here to switch tabs
Problem
Ask
Submissions

Problem: Sum of Mutated Array Closest to Target

med
30 min
Understand how to determine a mutation value to replace elements in an array greater than this value, so the resulting sum is closest to the target. Learn to apply sorting and binary search to efficiently solve this problem, practicing your skills in problem assessment and algorithm implementation.

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:

  • 11 \leqarr.length 103 \leq 10^3

  • 11 \leqarr[i], target 104\leq 10^4