Tap here to switch tabs
Problem
Submissions

Problem: Counting Bits

Counting Bits asks you to build an array for every number from zero through n, where each entry records how many one bits appear in that number's binary representation.

Statement

For a given positive integer, n, your task is to return an array of length n+1n+1 such that for each xx where 0≤x≤n0 \leq x \leq n, result[x] is the count of 11s in the binary representation of xx.

Constraints:

  • 0≤n≤1040 \leq n \leq 10^4
⋮
Tap here to switch tabs
Problem
Submissions

Problem: Counting Bits

Counting Bits asks you to build an array for every number from zero through n, where each entry records how many one bits appear in that number's binary representation.

Statement

For a given positive integer, n, your task is to return an array of length n+1n+1 such that for each xx where 0≤x≤n0 \leq x \leq n, result[x] is the count of 11s in the binary representation of xx.

Constraints:

  • 0≤n≤1040 \leq n \leq 10^4