All practice tasks

Coding (Algo)

Count Enabled Flags Across Records

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

4

Example 2

{
  "nums": [
    4294967295
  ]
}

Returns

32

Required complexity

O(32n) time and O(1) auxiliary space

What this task practices

Count Enabled Flags Across Records is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as easy difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.