Data Structures & AlgorithmsHard

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 and then strictly decreases (a purely increasing or purely decreasing block is not bitonic)?

  1. A. 3
  2. B. 6
  3. C. 4
  4. D. 7

Correct answer: B. 6

Scan with two states, rising then falling; a bitonic block has a single peak strictly inside it. Pure increasing or decreasing runs are excluded by the requirement of both phases.

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

Exams that ask this topic