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?
- A. 2 -1 2
- B. 2 -1 -1
- C. -1 2 -1
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the sum of the minimum of every contiguous window of size 4 in [8, 2, 6, 1, 9, 3, 7]?
- A jump game on [2, 3, 0, 1, 4, 0, 2, 1, 3] starts at index 0; from index i you may jump 1 to a[i] steps forward. What is the minimum…
- Balloons are intervals [1,6], [2,8], [7,12], [10,16] on a line. Arrows shot at integer points burst every balloon whose interval contains…
- Around a circular route, station i has gas[i] fuel and the trip to station i+1 costs cost[i]. With gas = [1, 2, 3, 4, 5] and cost = [3, 4…
- In one move you may increment all elements of an array except one by 1. What is the minimum number of moves to make all elements of [1, 5…
- Two arrays a = [1, 3, 5] and b = [2, 4, 6] are given. You may reorder b arbitrarily and pair a[i] with the i-th element of the reordered…