Leetcode 1662 Solution

This article provides solution to leetcode question 1662 (minimum-numbers-of-function-calls-to-make-target-array)

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