CodeOath
← All problems

Counting Bits

Easy
bit-manipulationdynamic-programming

Given an integer n, return an array result of length n + 1 where result[i] is the number of set bits (1s) in the binary representation of i, for every i from 0 to n.

Example:

Input: n = 5
Output: [0,1,1,2,1,2]

Constraints:

  • 0 <= n <= 10^5