Data Structures & AlgorithmsHard

What is the maximum sum of a contiguous subarray of 4 2 4 5 6 2 8 that contains NO repeated value?

  1. A. 31
  2. B. 25
  3. C. 16
  4. D. 23

Correct answer: B. 25

Use a sliding window with a last-seen index map; whenever a repeat enters, the left end jumps past its previous position. Ignoring the distinctness, limiting the length, or subtracting from the answer changes the result.

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

Exams that ask this topic