Data Structures & AlgorithmsModerate
What is the maximum AVERAGE over all contiguous subarrays of 1 12 -5 -6 50 3 that have length at least 3? Give the answer as a fraction in lowest terms.
- A. 53/2
- B. 51/4
- C. 47/3
- D. 50/1
Correct answer: C. 47/3
The best average under a length constraint is not always the maximum element, since longer blocks can average higher. Scanning all blocks of length at least 3 and comparing exact fractions gives the answer; allowing length 2 or fixing length 3 changes it.
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
- Choose two NON-OVERLAPPING contiguous windows of length exactly 2 from 4 -2 7 1 -5 6 3 -1. What is the largest possible total sum of their…
- How many contiguous subarrays of 3 1 2 4 0 contain EXACTLY 2 inversions (pairs i < j inside the subarray with a[i] > a[j])?
- What is the length of the longest contiguous subarray of 1 3 5 4 2 6 8 7 3 1 that is bitonic, meaning it strictly increases up to one peak…
- How many contiguous subarrays of 2 1 4 7 3 2 5 3 1 are mountains? A mountain has length at least 3, strictly increases to a single peak…
- In the sorted array 1 3 4 7 9 12 14, how many index pairs i < j satisfy A[j] − A[i] ≥ 5?
- Count the CIRCULAR descents of 3 4 5 1 2: positions i (0 ≤ i < n) where A[i] > A[(i+1) mod n], with the last element compared to the…