Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many index triples i < j < k in [2, 3, 5, 7, 8] satisfy a[k] - a[i] <= 4?

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

Correct answer: B. 3

Fix the left index i and extend k while the span stays within T; with sorted values the valid k form a prefix. The inequality is non-strict.

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

Exams that ask this topic