Data Structures & AlgorithmsVery hard
What is the minimum number of elements you must DELETE from 7 4 9 2 5 8 so that the sum of the remaining elements is divisible by 6? (Deleting nothing is allowed if it already works.)
- A. 2
- B. 1
- C. 0
- D. 3
Correct answer: B. 1
The sum of the kept elements must hit residue 0 mod 6, so try deletion sets of increasing size and check the residue of what remains. Counting elements divisible by 6 ignores combinations, and the mod-3 answer is a weaker requirement.
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
- In "xaybzaxxbab", what is the length of the shortest contiguous substring that contains the letter 'a' followed later by the letter 'b'…
- How many contiguous subarrays of 4 2 7 1 5 3 6 of length at least 2 have their FIRST element equal to their minimum?
- How many contiguous subarrays of 1 2 4 3 5 2 have XOR equal to their SUM?
- What is the length of the shortest contiguous subarray of 1 4 2 7 3 5 6 1 whose sum is at least 14?
- How many contiguous subarrays of 2 3 4 5 6 7 8 contain EXACTLY two even values and have an ODD length?
- How many index pairs i < j in 1 3 6 5 4 10 2 have A[i] + A[j] equal to a perfect square?