1300. Sum of Mutated Array Closest to Target Medium
1/**
2 * [1300] Sum of Mutated Array Closest to Target
3 *
4 * Given an integer array arr and a target value target, return the integer value such that when we change all the integers larger than value in the given array to be equal to value, the sum of the array gets as close as possible (in absolute difference) to target.
5 * In case of a tie, return the minimum such integer.
6 * Notice that the answer is not neccesarilly a number from arr.
7 *
8 * Example 1:
9 *
10 * Input: arr = [4,9,3], target = 10
11 * Output: 3
12 * Explanation: When using 3 arr converts to [3, 3, 3] which sums 9 and that's the optimal answer.
13 *
14 * Example 2:
15 *
16 * Input: arr = [2,3,5], target = 10
17 * Output: 5
18 *
19 * Example 3:
20 *
21 * Input: arr = [60864,25176,27249,21296,20204], target = 56803
22 * Output: 11361
23 *
24 *
25 * Constraints:
26 *
27 * 1 <= arr.length <= 10^4
28 * 1 <= arr[i], target <= 10^5
29 *
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/sum-of-mutated-array-closest-to-target/
34// discuss: https://leetcode.com/problems/sum-of-mutated-array-closest-to-target/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39 pub fn find_best_value(arr: Vec<i32>, target: i32) -> i32 {
40 0
41 }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn test_1300() {
52 }
53}
54
Back
© 2025 bowen.ge All Rights Reserved.