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)?
- A. 2
- B. 3
- C. 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.
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
- Looking from the right, a building is seen if it is strictly taller than every building to its right (the rightmost is always seen). How…
- A list holds 1 to 10. Every node whose 1-based position is a multiple of 3 is deleted. What is the sum of the remaining values?
- How many unordered index pairs i < j in [2, 3, 4, 5, 6] have a[i] + a[j] prime?
- How many distinct anagram classes are there among the words eat, tea, tan, ate, nat and bat (two words are in the same class if one is a…
- How many values x in [2, 4, 6, 7, 8] have both x - 1 and x + 1 present in the array?
- What is the length of the longest palindromic subsequence of the string agbdba?