Code RoomCounting bits
MediumPrep Room Coding #1600

Counting bits

CodingAlgorithms & data structuresMid–Senior~25 min

Given n, return an array where index i holds the number of 1 bits in i, for all i from 0 to n.

Implement
counting_bits(n: int) → list[int]
Examples
in[2]out[0,1,1]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 25 min
InputExpectedGot
[2][0,1,1]not run yetsample