Weigh the Permission Flags

Intermediate

A 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

Inputn = 13
Output3
Inputn = 0
Output0
Hints
  • Repeatedly add Math.mod(n,2) to a count and halve n until it reaches 0.
Anonymous Apex

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.