Search
⌘K
Get Premium
Leetcode 1558. Minimum Numbers of Function Calls to Make Target Array
Starting from zeros, you may increment any single element by 1 or double all elements; find the minimum calls to reach the target array. Key insight: work in binary — total increments = sum of set bits in nums, and total doubles = max bit-length of nums minus one (i.e., floor(log2(max(nums)))) — sum them for the answer.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
All Regions
Comments
Hello Interview Premium
Your account is free and you can post anonymously if you choose.