Data Structures & AlgorithmsModerateTCS NQT · GATE CS
What is the smallest integer x ≥ 100 whose binary representation contains exactly 4 ones?
- A. 101
- B. 102
- C. 100
- D. 104
Correct answer: A. 101
Scanning upward from N and testing the number of one-bits (popcount) finds the first match, which is exact. Adding k to N, or only looking at N's own bit count, gives values that need not have exactly k 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
- Items of sizes [4, 8, 1, 4, 2, 1] must be packed into bins of capacity 10 with no bin over capacity. What is the minimum number of bins…
- How many binary strings of length 8 contain no two adjacent 1s and an EVEN number of 0s?
- The string "abaccbbca" is split into contiguous palindromic pieces. A piece of length L costs L². What is the minimum total cost?
- What is the maximum sum of a contiguous subarray of [4, -1, 2, 2, 5, -3, 4, 1] that contains at most 2 distinct values?
- What is the minimum number of characters you must delete from "abbabaab" (keeping the order of the rest) so that the result contains NO…
- How many ordered pairs (i, j) with i ≠ j exist in [2, 4, 3, 8, 6, 9] such that a[j] is divisible by a[i]?