Tap here to switch tabs
Problem
Submissions

Problem: Sum of Values at Indices With K Set Bits

med
30 min
Try to solve the Sum of Values at Indices With K Set Bits problem.

Statement

You are given a 00-indexed integer array nums and an integer k.

Return an integer denoting the sum of elements in nums whose corresponding indices have exactly k set bits in their binary representation.

The set bits in an integer refer to the number of 11’s present in its binary form.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 1≤1 \leq nums[i] ≤105\leq 10^5

  • 0≤0 \leq k ≤10\leq 10

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Sum of Values at Indices With K Set Bits

med
30 min
Try to solve the Sum of Values at Indices With K Set Bits problem.

Statement

You are given a 00-indexed integer array nums and an integer k.

Return an integer denoting the sum of elements in nums whose corresponding indices have exactly k set bits in their binary representation.

The set bits in an integer refer to the number of 11’s present in its binary form.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 1≤1 \leq nums[i] ≤105\leq 10^5

  • 0≤0 \leq k ≤10\leq 10