Data Structures & AlgorithmsVery hardCodeforces Div2 C · GATE CS
Starting from the number 1, each operation either doubles the current number or adds 1. What is the minimum number of operations needed to reach exactly 100?
- A. 99
- B. 6
- C. 3
- D. 8
Correct answer: D. 8
Work backwards from 100 (1100100₂): halve when even, subtract 1 when odd: 100 → 50 → 25 → 24 → 12 → 6 → 3 → 2 → 1, i.e. 8 operations (6 doublings + 2 additions). 6 counts only doublings, 3 is the popcount, and 99 uses only +1.
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 pairs (i, j) with 1 ≤ i ≤ j ≤ 12 have lcm(i, j) ≤ 12?
- Coins of values 1, 4, 9 and 16 are available in unlimited supply. What is the minimum number of coins that makes exactly 27?
- What is the maximum sum of a contiguous subarray of [4, -3, 5, 2, -7, 6, 1, 3] whose length is ODD?
- How many contiguous subarrays of [2, 3, 5, 4, 7, 6, 9] contain EXACTLY two odd numbers?
- Among the windows of exactly 3 consecutive elements of [5, 2, 9, 1, 7, 3, 8, 4], what is the smallest window sum that is at least 15?
- How many triples (a, b, c) with a < b < c taken from the set [1, 2, 3, 4, 5, 6, 8, 10, 12] satisfy a + b = c?