Data Structures & AlgorithmsModerateTCS NQT · Codeforces Div2 B

Positions [15, 3, 22, 9, 40, 27] are given in arbitrary order. What is the largest difference between two consecutive positions when the positions are sorted?

  1. A. 31
  2. B. 10
  3. C. 37
  4. D. 13

Correct answer: D. 13

Sort, then take the maximum adjacent difference; the bound is at least (max − min)/(n − 1), but the answer needs sorted neighbours, not the input's neighbours. The overall range is always at least the answer and is not the same quantity.

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

Exams that ask this topic