LeetCode solutions

2356. Largest Combination With Bitwise AND Greater Than Zero

My accepted Python solution to LeetCode problem 2356, Largest Combination With Bitwise AND Greater Than Zero, running in 496ms.

  • Difficulty: Medium
  • Python
  • Runtime 496ms
  • Memory 25MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 496ms, memory 25MB, accepted 2026-01-02.

python
class Solution:
    def largestCombination(self, candidates: List[int]) -> int:
        result = 0
        for bit in range(24):  # Numbers up to 10^7 need at most 24 bits
            count = sum(1 for num in candidates if num & (1 << bit))
            result = max(result, count)
        return result

Source