FastPrepCount the 1 Bits in a 32-Bit Value
Problems/Count the 1 Bits in a 32-Bit Value

Count the 1 Bits in a 32-Bit Value

Amazon logoAmazon● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: In the first round of an Amazon senior firmware and BIOS engineer interview, with the hiring manager and a teammate, one coding task was to count the 1 bits of a number. The report names the task and nothing else.

It gives no input type, examples or limits. Here, the input is an unsigned 32-bit value passed as a number from 0 to 2^32 - 1, the answer is how many of its bits are 1, and the examples are ours.

Our version is about 90% the same as the reported question.

You are given a non-negative integer n that fits in 32 unsigned bits, so n is between 0 and 2^32 - 1.

Return the number of bits of n that are 1 when n is written in binary.

Function

countOneBits(n: long) → int

Examples

Example 1

n = 11return = 3

11 in binary is 1011, which has three 1 bits.

Example 2

n = 128return = 1

128 is 2^7, so its binary form 10000000 has one 1 bit.

Example 3

n = 4294967295return = 32

4294967295 is 2^32 - 1, the largest allowed value. All 32 of its bits are 1.

Constraints

  • 0 <= n <= 2^32 - 1

More Amazon Phone Screen questions

  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 3SumPHONE SCREEN · Seen Nov 2026
  • Circular Primes Below a LimitPHONE SCREEN · Seen Nov 2026
  • Cheapest Flights Within K StopsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Two SumOA · PHONE SCREEN · Seen Nov 2026
  • Reverse a StringPHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Even or Odd Without DivisionAdobe · PHONE SCREENAdobe interview questions
  • Power of Two Without DivisionArm · PHONE SCREEN
  • Powers of Two in a RangeAkuna Capital · PHONE SCREENAkuna Capital interview questions
  • Choose the Next Minesweeper ActionRunloop · PHONE SCREEN
  • IP Address to CIDR BlocksOpenAI · PHONE SCREENOpenAI interview questions
  • Fewest Games to Find the Top Two TeamsSusquehanna International Group (SIG) · PHONE SCREENSusquehanna International Group (SIG) interview questions
  • Minimum Testers to Find the Poisoned BottleWalleye Capital · OA
  • Address on Same PageNVIDIA · OANVIDIA interview questions
  • Find the Missing Number from 1 to nHyperVerge · ONSITE INTERVIEW
  • Find the Missing Number from 1 to nGEP · OA

Amazon interview experiences

  • Amazon SWE OA with AI Coding: 1 Experience
  • Amazon SWE Intern Phone Screen Interview Experience: 1 Experience
  • Amazon New Grad SDE I OA and Virtual Onsite: 1 Experience
  • Amazon BIE Intern SQL and Interview Questions: 17 Experiences
  • Amazon Experienced SWE AI-Assisted Debugging OA: 1 Experience
  • Amazon SDE II (L5) Interview Questions: 5 Experiences
See Amazon hiring insights
Saved
class Solution {
    public int countOneBits(long n) {
        // Write your code here.
    }
}
Checking account…