arrow_back Back to Challenges

#338 Counting Bits

Easy Acceptance 0%
description

Problem Description

Given an integer `n`, return an array `ans` of length `n + 1` such that for each `i` (`0 <= i <= n`), `ans[i]` is the number of `1`'s in the binary representation of `i`.

checklist Constraints

0 <= n <= 10^5

science Examples

Case #1

In: n = 5
Out: [0,1,1,2,1,2]

Case #2

In: n = 2
Out: [0,1,1]

Mastery Tags

Bit Manipulation Dynamic Programming

Hiring Companies

Amazon Google Microsoft
code

Integrated IDE

code_blocks
Coding
psychology
Aptitude