Data Structures & AlgorithmsModerateGATE CS · ICPC regional

In the circular array [1, 2, 1], what is the next greater element of the element at index 2 (search continues around the circle, -1 if no greater value exists)?

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

Correct answer: A. 2

Scan circularly from index 2: the next index is 0 (value 1, not greater), then index 1 with value 2, which is greater. Stopping after one lap would miss it.

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

Exams that ask this topic