Minimum Non-Zero Product of the Array Elements

You are given a positive integer p. Consider an array nums (1-indexed) that consists of the integers in the inclusive range [1, 2^p - 1] in their binary representations.

You are allowed to perform the following operation any number of times:

  • Choose two elements x and y from nums.
  • Choose a bit in x and swap it with its corresponding bit in y; corresponding bit means the bit in the same position in the other integer.

Find the minimum non-zero product of nums after performing the operation any number of times. Return this product modulo 10^9 + 7.

Note: The answer should be the minimum product before the modulo operation is done.

Example 1
Inputp = 1
Output1
There is only one element, so the product equals that element.
Example 2
Inputp = 2
Output6
Any swap would either make the product 0 or keep the same product, so 1 * 2 * 3 = 6 is already minimized.

Constraints

  • 1 <= p <= 60

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate