Data Structures & AlgorithmsHardGATE CS · TCS NQT

Among integers from 1 to 40 inclusive, which value has the largest number of 1-bits in binary? Report the smallest such value.

  1. A. 32
  2. B. 31
  3. C. 39
  4. D. 40

Correct answer: B. 31

The 1-bit count is maximised by 31 (11111, five bits). Among numbers up to 40 the smallest with five ones is 31, and 39 has four ones.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic