Data Structures & AlgorithmsHardGATE CS · competitive programming

In the circular array [1, 5, 3, 4, 2], what is the next greater element of the value 2 at index 4, when the search wraps past the end?

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

Correct answer: C. 5

Wrapping checks index 0 (value 1, not greater) and then index 1 (value 5, the first greater value). A search that does not wrap would wrongly report that no greater element exists.

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

Exams that ask this topic