#3674

Minimum Operations to Equalize Array

easy · 60.1% accepted · 58 likes · top 58%

array · bit manipulation · brainteaser

Description

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.

A subarray is a contiguous non-empty sequence of elements within an array.

Solution