3674. Minimum Operations to Equalize Array Easy

@problem@discussion
#Array#Bit Manipulation#Brainteaser



1/**
2 * [3674] Minimum Operations to Equalize Array
3 *
4 * You are given an integer array nums of length n.
5 * In one operation, choose any subarray nums[l...r] (0 <= l <= r < n) and replace each element in that subarray with the bitwise AND of all elements.
6 * Return the minimum number of operations required to make all elements of nums equal.
7 * A subarray is a contiguous non-empty sequence of elements within an array.
8 *  
9 * <strong class="example">Example 1:
10 * <div class="example-block">
11 * Input: <span class="example-io">nums = [1,2]</span>
12 * Output: <span class="example-io">1</span>
13 * Explanation:
14 * Choose nums[0...1]: (1 AND 2) = 0, so the array becomes [0, 0] and all elements are equal in 1 operation.
15 * </div>
16 * <strong class="example">Example 2:
17 * <div class="example-block">
18 * Input: <span class="example-io">nums = [5,5,5]</span>
19 * Output: <span class="example-io">0</span>
20 * Explanation:
21 * nums is [5, 5, 5] which already has all elements equal, so 0 operations are required.
22 * </div>
23 *  
24 * Constraints:
25 * 
26 * 	1 <= n == nums.length <= 100
27 * 	1 <= nums[i] <= 10^5
28 * 
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/minimum-operations-to-equalize-array/
33// discuss: https://leetcode.com/problems/minimum-operations-to-equalize-array/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38    pub fn min_operations(nums: Vec<i32>) -> i32 {
39        0
40    }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn test_3674() {
51    }
52}
53

Back
© 2026 bowen.ge All Rights Reserved.