Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Minimum Operations to Equalize Array

XPChallenge Points: 10
levelLevel: Easy

You are given an array nums.
You can perform the following operation:

  • Select any subarray nums[l...r].

  • Replace every element in that subarray with the bitwise AND of all numbers in that subarray.

Your goal is to make all elements in the array equal.

Return the minimum number of such operations required.

Example 1:

Input: nums = [7, 7, 7, 7]

Output: 0

Explanation:

All elements are already equal.

Example 2:

Input: nums = [8, 4, 2]

Output: 0

Explanation:

After two AND operations on chosen subarrays, all values can be made equal.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result