2918. Minimum Equal Sum of Two Arrays After Replacing Zeros Medium
1/**
2 * [2918] Minimum Equal Sum of Two Arrays After Replacing Zeros
3 *
4 * You are given two arrays nums1 and nums2 consisting of positive integers.
5 * You have to replace all the 0's in both arrays with strictly positive integers such that the sum of elements of both arrays becomes equal.
6 * Return the minimum equal sum you can obtain, or -1 if it is impossible.
7 *
8 * <strong class="example">Example 1:
9 *
10 * Input: nums1 = [3,2,0,1,0], nums2 = [6,5,0]
11 * Output: 12
12 * Explanation: We can replace 0's in the following way:
13 * - Replace the two 0's in nums1 with the values 2 and 4. The resulting array is nums1 = [3,2,2,1,4].
14 * - Replace the 0 in nums2 with the value 1. The resulting array is nums2 = [6,5,1].
15 * Both arrays have an equal sum of 12. It can be shown that it is the minimum sum we can obtain.
16 *
17 * <strong class="example">Example 2:
18 *
19 * Input: nums1 = [2,0,2,0], nums2 = [1,4]
20 * Output: -1
21 * Explanation: It is impossible to make the sum of both arrays equal.
22 *
23 *
24 * Constraints:
25 *
26 * 1 <= nums1.length, nums2.length <= 10^5
27 * 0 <= nums1[i], nums2[i] <= 10^6
28 *
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/minimum-equal-sum-of-two-arrays-after-replacing-zeros/
33// discuss: https://leetcode.com/problems/minimum-equal-sum-of-two-arrays-after-replacing-zeros/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38 pub fn min_sum(nums1: Vec<i32>, nums2: Vec<i32>) -> i64 {
39
40 }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn test_2918() {
51 }
52}
53
Back
© 2025 bowen.ge All Rights Reserved.