terminal
Elevo
/
ESC
Login
Initiate Registration
code
Topics
corporate_fare
Companies
history
History
arrow_back
Back to Challenges
#338
Counting Bits
Easy
Acceptance 0%
Editorial
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
Python 3
expand_more
C
C++ 17
Java
JavaScript
Python 3
C
C++ 17
Java
JavaScript
Python 3
refresh
class Solution: def countBits(self, n: int) -> list[int]: pass
Login to Compile
Processing
terminal
Debug Output
home
Home
extension
Practice
robot_2
login
Sign In
account_circle
Menu
code_blocks
Coding
psychology
Aptitude
Navigation
close
Login
Registration