Data Structures & AlgorithmsHard

Consider the windows of length 3 of 1 2 3 1 2 4 1 2 starting at positions i and i+1. How many i satisfy sum(window i) = sum(window i+1)?

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

Correct answer: A. 4

Two consecutive windows of length 3 have equal sums exactly when the entering element equals the leaving element, so this reduces to a comparison of A[i] with A[i+3]. Checking strict inequality or the wrong window pair answers a different question.

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

Exams that ask this topic