Data Structures & AlgorithmsVery hard

What is the maximum sum of a contiguous subarray of 3 1 3 2 4 1 5 whose elements are all DISTINCT?

  1. A. 19
  2. B. 10
  3. C. 15
  4. D. 16

Correct answer: C. 15

Sliding windows with a last-seen index map keep the window distinct while tracking the running sum. Ignoring the distinctness, restricting the length, or adding one wrongly gives other answers.

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

Exams that ask this topic