Data Structures & AlgorithmsModerateTCS NQT · Codeforces Div2 B

Among the windows of exactly 3 consecutive elements of [4, 2, 4, 1, 3, 5, 2, 6] whose 3 values are all different, what is the largest window sum?

  1. A. 14
  2. B. 8
  3. C. 18
  4. D. 13

Correct answer: D. 13

Check distinctness with a count per window (or a sliding window with counts), then take the best sum among the valid windows. Ignoring the distinctness test picks windows such as 4, 2, 4 that a reader might mistake for valid.

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

Exams that ask this topic