Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
What is the smallest integer greater than 13 that has the same number of 1-bits as 13 in binary?
- A. 11
- B. 19
- C. 22
- D. 14
Correct answer: D. 14
13 = 1101₂; the next number with three set bits moves the lowest movable 1 up one place: 1110₂ = 14. 11 = 1011₂ is the previous such number, and 19 = 10011₂ and 22 = 10110₂ also have three bits but are not the smallest above 13.
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
- Convert a(b+c)-d/e to postfix with the shunting-yard algorithm (+ and - have lower precedence than and /; all operators are…
- Evaluate the prefix (Polish) expression - 3 + 2 4 5. What is the value?
- How many windows of size 4 in the array [4, 2, 12, 3, 8, 1, 9, 5] have their maximum at the first position of the window (ties with a…
- In the array [1, 4, 2, 6, 5, 7], a value is a record if it is strictly greater than every value before it. What is the sum of all record…
- What is the maximum nesting depth of the parentheses in the string a(b(c)d)(e(f(g))) ?
- How many elements of [1, 5, 2, 8, 3, 9, 4] are strict local maxima (strictly greater than both neighbours; the two end elements are…