#3131
Easy Algorithms Find the integer added to array i
Array
82.9% acceptance
Feb 23, 2026
172
11
You are given two arrays of equal length, nums1 and nums2.
Each element in nums1 has been increased (or decreased in the case of negative) by an integer, represented by the variable x.
As a result, nums1 becomes equal to nums2. Two arrays are considered equal when they contain the same integers with the same frequencies.
Return the integer x.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn added_integer(nums1: Vec<i32>, nums2: Vec<i32>) -> i32 {
nums2.iter().min().unwrap() - nums1.iter().min().unwrap()
}
}