Weigh the Permission Flags
Intermediate SolvedA permission set is packed into an integer bitmask. To audit it you need the count of enabled flags — the number of 1-bits in the binary form of a non-negative integer.
Implement `solve(Integer n)` (non-negative) to return the number of 1-bits in its binary representation.
Examples
Input
n = 13Output
3Input
n = 0Output
0Hints
- Repeatedly add Math.mod(n,2) to a count and halve n until it reaches 0.
Tests
Your code runs in a secure sandbox against multiple hidden test cases. The problem is solved only when every test passes. Each run is isolated and any data changes are rolled back automatically.