Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

How many contiguous subarrays of [2, 4, 3, 1, 5, 7, 6] consist of consecutive integers (all distinct, with max minus min equal to length minus one)?

  1. A. 15
  2. B. 13
  3. C. 14
  4. D. 17

Correct answer: C. 14

Such a subarray is a set of distinct consecutive integers exactly when max - min = length - 1. Checking that condition for each window (with a sparse table or deques) gives the answer; the length-only test alone is too weak.

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

Exams that ask this topic