A settings export stores 32 feature toggles in one signed 32-bit integer, mask, one bit per toggle. Negative values are normal: they just mean the toggle in bit 31 is on.
Write enabledCount(mask) that returns how many of the 32 bits are 1, reading negative numbers in two's complement (so -1 has all 32 bits on).
Input: mask = 11 Output: 3
11 is 1011 in binary: three bits are on.
Input: mask = -1 Output: 32
In two's complement, -1 is 32 ones.
-2^31 <= mask <= 2^31 - 1Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #678 Count Enabled Flags. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.