2859. Sum of Values at Indices With K Set Bits

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2859

class Solution:
    def sumIndicesWithKSetBits(self, nums: List[int], k: int) -> int:
        return sum(x for i, x in enumerate(nums) if i.bit_count() == k)