3132. Find the Integer Added to Array II Medium
1/**
2 * [3132] Find the Integer Added to Array II
3 *
4 * You are given two integer arrays nums1 and nums2.
5 * From nums1 two elements have been removed, and all other elements have been increased (or decreased in the case of negative) by an integer, represented by the variable x.
6 * As a result, nums1 becomes equal to nums2. Two arrays are considered equal when they contain the same integers with the same frequencies.
7 * Return the minimum possible integer x that achieves this equivalence.
8 *
9 * <strong class="example">Example 1:
10 * <div class="example-block">
11 * Input: <span class="example-io" style="
12 * font-family: Menlo,sans-serif;
13 * font-size: 0.85rem;
14 * ">nums1 = [4,20,16,12,8], nums2 = [14,18,10]</span>
15 * Output: <span class="example-io" style="
16 * font-family: Menlo,sans-serif;
17 * font-size: 0.85rem;
18 * ">-2</span>
19 * Explanation:
20 * After removing elements at indices [0,4] and adding -2, nums1 becomes [18,14,10].
21 * </div>
22 * <strong class="example">Example 2:
23 * <div class="example-block">
24 * Input: <span class="example-io" style="
25 * font-family: Menlo,sans-serif;
26 * font-size: 0.85rem;
27 * ">nums1 = [3,5,5,3], nums2 = [7,7]</span>
28 * Output: <span class="example-io" style="
29 * font-family: Menlo,sans-serif;
30 * font-size: 0.85rem;
31 * ">2</span>
32 * Explanation:
33 * After removing elements at indices [0,3] and adding 2, nums1 becomes [7,7].
34 * </div>
35 *
36 * Constraints:
37 *
38 * 3 <= nums1.length <= 200
39 * nums2.length == nums1.length - 2
40 * 0 <= nums1[i], nums2[i] <= 1000
41 * The test cases are generated in a way that there is an integer x such that nums1 can become equal to nums2 by removing two elements and adding x to each element of nums1.
42 *
43 */
44pub struct Solution {}
45
46// problem: https://leetcode.com/problems/find-the-integer-added-to-array-ii/
47// discuss: https://leetcode.com/problems/find-the-integer-added-to-array-ii/discuss/?currentPage=1&orderBy=most_votes&query=
48
49// submission codes start here
50
51impl Solution {
52 pub fn minimum_added_integer(nums1: Vec<i32>, nums2: Vec<i32>) -> i32 {
53 0
54 }
55}
56
57// submission codes end
58
59#[cfg(test)]
60mod tests {
61 use super::*;
62
63 #[test]
64 fn test_3132() {
65 }
66}
67
Back
© 2025 bowen.ge All Rights Reserved.