Data Structures & AlgorithmsModerateTCS NQT · Infosys

How many DISTINCT sums appear among the windows of exactly 3 consecutive elements of [4, 1, 4, 2, 1, 4, 2]?

  1. A. 5
  2. B. 3
  3. C. 2
  4. D. 1

Correct answer: C. 2

There are n − k + 1 windows, but equal sums collapse in the set. Counting windows gives the larger number, and counting distinct elements answers a different question.

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

Exams that ask this topic