Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Number of 1 Bits

Easy
bit-manipulation

Return the number of set bits (the Hamming weight) in the binary representation of a non-negative integer n.

Input: one line, the integer n. Output: the count of 1 bits.

Example 1
Input:
11
Output:
3

1011₂.

Example 2
Input:
128
Output:
1

10000000₂.

Constraints

  • 0 ≤ n ≤ 2^31 − 1
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.