Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

What is the length of the longest contiguous subarray of [1, 5, 6, 2, 8, 3] whose maximum minus minimum is at most 3?

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

Correct answer: B. 2

The longest window with spread at most 3 is [5, 6] of length 2. The window [5, 6, 2] has spread 4 and is excluded.

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

Exams that ask this topic