Data Structures & AlgorithmsHardCodeforces Div2 B-D · ICPC regional

For the circular array [1, 2, 1], the next greater element of each position searches forward and wraps around to the start, with -1 when none exists. Which list of answers results?

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

Correct answer: A. 2 -1 2

Circular NGE needs a doubled traversal of length 2n. Position 0 finds 2, position 1 has no larger value even after wrapping, and position 2 wraps to find 2.

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

Exams that ask this topic