Sum of Values at Indices With K Set Bits
A easy-tier problem at 86% community acceptance, tagged with Array, Bit Manipulation. Reported in interviews at Accenture and 0 others.
Sum of Values at Indices With K Set Bits is an easy problem that combines array iteration with bit counting. It's straightforward on the surface, but the trick is understanding how to efficiently count set bits in an index and know when to sum. Accenture has asked it. With an 85% acceptance rate, this looks like a warm-up, but a surprising number of candidates stumble on the bit-counting step or misread what "K set bits" means. If you hit this during an assessment and blank on the bitwise trick, StealthCoder solves it in seconds, invisible to the proctor.
Companies that ask "Sum of Values at Indices With K Set Bits"
Sum of Values at Indices With K Set Bits is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code.
Get StealthCoderThe problem asks you to sum array values where the index itself has exactly K bits set to 1 in binary. Most candidates understand the array loop part instantly, but the blocker is usually the bit-counting logic. You need a function that counts the number of 1s in the binary representation of an integer (often called popcount or Hamming weight). Some try to manually count bits with loops and mod operations. That works but adds unnecessary friction. Python's built-in bin() and count(), or bit manipulation tricks like Brian Kernighan's algorithm, are cleaner. The acceptance rate suggests most people get it right, but the time pressure of a live assessment can make that bit-counting step feel unfamiliar. StealthCoder eliminates that uncertainty by surfacing the correct approach in real time.
Pattern tags
You know the problem.
Make sure you actually pass it.
Sum of Values at Indices With K Set Bits recycles across companies for a reason. It's easy-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Sum of Values at Indices With K Set Bits interview FAQ
What does 'K set bits' actually mean?+
A set bit is a 1 in the binary representation of a number. If K is 2, you're looking for indices whose binary form has exactly two 1s. For example, 3 is binary 11 (two set bits), 5 is binary 101 (two set bits), 6 is binary 110 (two set bits). Only sum values at those positions.
How do I count set bits efficiently?+
Most languages have a built-in. Python: bin(n).count('1'). Java: Integer.bitCount(n). C++: __builtin_popcount(n). If you need to roll your own, Brian Kernighan's algorithm removes one bit per iteration, scaling with the number of set bits rather than the bit width. It's elegant but the built-ins are faster.
Is this still asked at Accenture?+
Accenture has reported asking this problem. It's marked easy and the acceptance rate is high, so it likely serves as a screening-round warm-up to verify you can write clean code under time pressure rather than a hard discriminator.
What's the time complexity?+
O(n) to iterate the array once, and bit-counting is O(log m) where m is the largest index value. In practice, index values are bounded by array length, so this is O(n) overall. Space is O(1) if you don't count the output.
Are there gotchas I should watch for?+
Off-by-one errors are rare here because you're using indices directly. The main trap is misunderstanding the problem: sum values where index has K set bits, not where value has K set bits. Double-check the problem statement. Also, confirm whether indices are 0-indexed or 1-indexed in the problem's examples.
Want the actual problem statement? View "Sum of Values at Indices With K Set Bits" on LeetCode →