Data Structures & AlgorithmsHard

How many contiguous subarrays of 3 1 2 2 4 3 5 consist of consecutive integers (their values, in some order, are k, k+1, …, k+L−1 with no repeats)?

  1. A. 16
  2. B. 15
  3. C. 6
  4. D. 13

Correct answer: D. 13

A block of distinct integers is a run of consecutive values exactly when its spread equals its length minus one. Testing distinctness alone or the spread alone admits blocks that fail the other condition.

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

Exams that ask this topic