Data Structures & AlgorithmsVery hardGATE CS · DSA

A mountain is a contiguous subarray of length ≥ 3 that strictly increases to a single peak and then strictly decreases. What is the length of the longest mountain in [6, 4, 7, 8, 8, 5, 3, 7, 7, 8, 1, 2] (0 if none)?

  1. A. 5
  2. B. 2
  3. C. 3
  4. D. 4

Correct answer: C. 3

For each peak, extend left while values strictly rise towards it and right while they strictly fall; plateaus break a mountain. The longest has length 3.

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

Exams that ask this topic