Data Structures & AlgorithmsHard
For each contiguous subarray of 4 2 7 1 5 3 6 2, locate the FIRST position (in the original array) where its minimum value occurs. How many subarrays have that position at an ODD index?
- A. 32
- B. 4
- C. 16
- D. 33
Correct answer: A. 32
Use the absolute index of the first minimum within the subarray, not its relative position, since the question is about the array index. Using the relative position, or the even-index count, gives different totals.
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 contiguous subarrays of 2 7 1 8 2 8 of length at least 2 have a sum that leaves remainder 1 when divided by 4?
- How many contiguous subarrays of 5 1 6 2 7 3 8 contain EXACTLY two values that are at least 5?
- What is the length of the longest contiguous subarray of 1 6 2 7 3 5 4 8 1 9 that contains equally many values ≥ 5 and values < 5?
- How many contiguous subarrays of 3 5 7 2 9 1 13 have a product that leaves remainder 1 when divided by 4?
- How many contiguous subarrays of 4 1 3 2 6 1 have a sum STRICTLY greater than the sum of the elements outside them?
- How many NON-EMPTY prefixes of 3 2 5 1 4 5 2 (the first k elements, k ≥ 1) have a sum divisible by 5?