[LeetCode] Minimum Operations to Equalize Array

3674. Minimum Operations to Equalize Array

You are given an integer array nums of length n.

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.

Return the minimum number of operations required to make all elements of nums equal.

subarray

non-empty

1
2
3
4
5
6
class Solution {
public:
int minOperations(vector<int>& nums) {
return *max_element(begin(nums), end(nums)) != *min_element(begin(nums), end(nums));
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2026/09/04/PS/LeetCode/minimum-operations-to-equalize-array/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.