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.

  1. A. 53/2
  2. B. 51/4
  3. C. 47/3
  4. 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.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic