Data Structures & AlgorithmsModerate
How many contiguous subarrays of 2 4 3 6 1 5 have a sum that is divisible by the number of DISTINCT values in them?
- A. 10
- B. 11
- C. 2
- D. 9
Correct answer: A. 10
Compute the distinct count of each subarray first, then test the sum against it. Using the length instead of the distinct count, or the complement, changes which blocks qualify.
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 every window of exactly 3 consecutive elements of 7 3 9 4 8 2 6, compute (maximum − minimum) inside that window. What is the SMALLEST…
- A sorted linked list holds 1 2 2 3 3 3 4 4 4 4. Delete nodes so that each value keeps AT MOST TWO nodes, preserving order. How many nodes…
- How many different valid sequences of PUSH and POP operations are there for a stack that performs exactly 6 pushes and 6 pops in total…
- How many contiguous subarrays of 3 1 2 4 2 3 1 2 have a sum EXACTLY equal to twice their length?
- What is the maximum sum of a contiguous subarray of 4 2 4 5 6 2 8 that contains NO repeated value?
- How many contiguous subarrays of length at least 2 of 1 1 2 2 2 3 1 1 1 1 consist of ONE repeated value?