Bit manipulation · Easy
Each record stores 32 independent flags in an unsigned mask. An audit needs the total number of enabled flags across all records, not the number of distinct flag positions. Repeated records therefore contribute repeatedly.
Count all set bits across every supplied 32-bit mask and return their total.
Input
Call
- Implement solve(input) and return the result. The provided adapter handles JSON input and output.
Input shape
{ nums: unsigned32[] }
Fields
- nums contains unsigned 32-bit integers from 0 through 4294967295. Values with bit 31 set are positive JSON integers.
Output
Return value
- Return an integer count. Count each set bit of each occurrence separately.
- Zero masks contribute zero and an empty array returns zero.
Constraints
- 0 <= nums.length <= 100000. The largest answer is 3200000.
Examples
Example 1
{
"nums": [
3,
3
]
}Returns
4Example 2
{
"nums": [
4294967295
]
}Returns
32Required complexity
O(32n) time and O(1) auxiliary space