Data Structures & AlgorithmsModerate

How many index triples i < j < k in 1 2 3 4 5 6 7 satisfy A[i] + A[j] = A[k]?

  1. A. 22
  2. B. 0
  3. C. 9
  4. D. 10

Correct answer: C. 9

Enumerate index triples with i < j < k and test the sum against the third value. Using ≤ counts too many triples, counting pairs ignores the position of the third value, and testing a different arrangement answers another question.

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

Exams that ask this topic