Coding Challenge

Counting Bits

Easy
bit-manipulationdynamic-programming

Return the bit count for every number from 0 to n.

Given a non-negative integer n, return an array where answer[i] is the number of set bits in i for every 0 <= i <= n.

Examples

Input: n = 5

Output: [0,1,1,2,1,2]

Constraints

  • 0 <= n

Preparing your coding workspace...