Minimum Non-Zero Product of the Array Elements LeetCode solution in JavaScript

1
var minNonZeroProduct = function (p) {
2
p = BigInt(p);
3

4
const MOD = BigInt(1e9 + 7);
5
const first = (1n << p) - 1n;
6

7
const half = first / 2n;
8

9
const second = powMOD(first - 1n, half);
10

11
return (first * second) % MOD;
12

13
function powMOD(num, exp) {
14
if (exp === 0n) return 1n;
15

16
const tmp = powMOD(num, exp >> 1n);
17

18
let res = (tmp * tmp) % MOD;
19

20
if (exp % 2n) res = (res * num) % MOD;
21

22
return res;
23
}
24
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0