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.
- A. 32
- B. 31
- C. 39
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many index pairs i < j of [1, 2, 3, 4, 6, 6] satisfy a[i] a[j] = a[i] + a[j]?
- How many distinct values v occur in [5, 1, 2, 3, 9, 10, 4] such that v + 1 also occurs in the array?
- Closed meeting intervals [1,3], [3,4], [2,5], [6,7] cannot share a room if they overlap even at one point. What is the minimum number of…
- How many inversions does the array [-3, -1, -2] have (pairs i < j with a[i] > a[j])?
- In "abcabdabc", how many positions i >= 1 start an occurrence of the prefix "abc" (the first three characters)?
- What is the sum of all integers from 1 to 50 inclusive that are coprime to 50?