LeetCode solutions

3605. Construct the Minimum Bitwise Array I

My accepted Python solution to LeetCode problem 3605, Construct the Minimum Bitwise Array I, running in 127ms.

  • Difficulty: Easy
  • Python
  • Runtime 127ms
  • Memory 17.5MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 127ms, memory 17.5MB, accepted 2026-01-01.

python
class Solution:
    def minBitwiseArray(self, nums: List[int]) -> List[int]:
        result = []
        for num in nums:
            found = False
            for ans in range(num + 1):
                if (ans | (ans + 1)) == num:
                    result.append(ans)
                    found = True
                    break
            if not found:
                result.append(-1)
        return result

Source