Exercises/#85 Counting Bits
#85

Counting Bits

Easy⚡ Bit Manipulation
50 XP

Problem

Given an integer n, return an array of length n+1 where ans[i] is the number of 1's in the binary representation of i.

Examples

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

Input: n=5
Output: [0,1,1,2,1,2]
bit-manipulationdynamic-programming
AI Assistant— powered by AI

Unlock hints progressively — start gentle, go deeper only if needed.

💡

Level 1: Gentle Nudge

A subtle direction

🗺️

Level 2: Approach

The algorithm to use

🔍

Level 3: Detailed

Step-by-step guidance

85 / 150

Your Solution

⚡ JavaScript

to save progress and use AI features