Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
Each operation doubles one element of [4, 8, 16, 2]. What is the minimum number of operations needed to make all four elements equal?
- A. 10
- B. 3
- C. 14
- D. 6
Correct answer: D. 6
Doubling can only raise values, so the cheapest common target is the maximum, 16: 4 needs 2, 8 needs 1, 2 needs 3, total 6. Aiming one power higher (32) costs 10, 3 counts elements rather than operations, and 14 adds 1 each time (16 − 2) instead of doubling.
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
- For the positive array [2, 1, 3, 4, 1], how many contiguous subarrays have a sum at most 5?
- How many contiguous subarrays of [1, 2, 1, 3, 4, 2, 3] contain exactly 3 distinct values?
- How many contiguous subarrays of [2, 8, 3, 2, 6, 1] have a product that is a perfect square?
- What is the minimum number of characters that must be deleted from "abcbdab" to make it a palindrome?
- How many pairs of non-overlapping equal substrings of length 2 exist in "abababab" (positions i < j with j >= i + 2)?
- In the text "aaabaaaabaaa", count the occurrences of "aaa" whose starting index is a prime number (0-indexed).