Skip to content

Practice Sum of Values at Indices With K Set Bits

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#2859
LeetCode Problem

Sum of Values at Indices With K Set Bits

Problem Statement

You are given a 0-indexed integer array nums and an integer k. Return an integer that denotes the sum of elements in nums whose corresponding indices have exactly k set bits in their binary representation. The set bits in an integer are the 1's present when it is written in binary.

Source: Sum of Values at Indices With K Set Bits on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [5,10,1,5,2], k = 1
Output
13

# Example 2

Input
nums = [4,3,2,1], k = 2
Output
1

Constraints

1 <= nums.length <= 1000
1 <= nums[i] <= 10^5
0 <= k <= 10

Related LeetCode Problems

Practice more problems similar to Sum of Values at Indices With K Set Bits.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.