Skip to main content

Number of 1 Bits

Problem Statement:​

Given a positive integer n. Your task is to return the count of set bits.

  • Example:

    Examples:

    Input:n = 6
    Output:2
    Explanation:Binary representation is '110', so the count of the set bit is 2.
    Input: n =8
    Output:1
    Explanation:Binary representation is '1000', so the count of the set bit is 1.

    Input: n =3
    Output:2

🚀 Level Up Your Engineering Mindset

Never Study in Isolation. Join Binary Dose.

Connect with fellow engineers, clear conceptual doubts, and get 2 visual breakdowns & engineering mental models daily across our community channels.

Discord
Official Hub

Discord Community

Start at #welcome-and-rules, say hello in #general-chat, clear doubts, and collaborate with engineers worldwide.

Join Discord Server→
⚡
Daily Knowledge Drops

Daily Visual Deep-Dives

Bite-sized system design schematics, core OS internals, and DSA intuition served right into your feeds every single day.

💡Have handwritten notes, cheat-sheets, or want to publish a technical article?
Learn How to Contribute→