Solution 1
- TimeO(n log m)
- SpaceO(1)
Where, n is number of elements in nums, m is maximum value in nums.
DID NOT GO THROUGH THE SOLUTION YET!
Python · 2026-01-20
class Solution:
'''
Time Complexity: O(n log m)
Space Complexity: O(1)
Where, n is number of elements in nums, m is maximum value in nums.
DID NOT GO THROUGH THE SOLUTION YET!
'''
def minBitwiseArray(self, nums: List[int]) -> List[int]:
ans = []
for m in nums:
if m == 2:
ans.append(-1)
else:
t = 0
x = m
while x & 1:
t += 1
x >>= 1
ans.append(m - (1 << (t - 1)))
return ans