Leetcode 1662 Solution
This article provides solution to leetcode question 1662 (minimum-numbers-of-function-calls-to-make-target-array)
Access this page by simply typing in "lcs 1662" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/minimum-numbers-of-function-calls-to-make-target-array
Solution
class Solution:
def minOperations(self, nums: List[int]) -> int:
ans = 0
max_len = 0
for num in nums:
if num == 0:
continue
max_len = max(max_len, int(math.log2(num)))
while num:
ans += 1
num &= num - 1
return ans + max_len