Question: Ninja has a circular array Nums containing N positive integers. An array is called circular if we consider the first element as next of the

Ninja has a circular array Nums containing N positive integers. An array is called circular if we consider the first element as next of the last element. Ninja wants you to find the first greater number to the right of each element in the array, if there is no greater element to the right of an element, then output -1 for this element. Example : If N = 5 and the array is: [ 1, 6, 4, 3, 5 ] We will return [ 6, -1, 5, 5, 6 ] because 6 is the first element to the right of 1 that is greater than 1, no element exists that is greater than 6, 5 is the first element to the right of 4 that is greater than 4, 5 is the first element to the right of 3 that is greater than 3, 6 is the first element to the circular right of 5 that is greater than 5.

Input Format : The first line contains a single integer T denoting the number of test cases, then each test case follows: The first line of each test case contains a single integer N denoting the size of the array. The second line of each test case contains N positive integers denoting the array elements Nums[i]. Output Format: For each test case, print the next greater elements for each element in the circular array. Output for each test case will be printed in a separate line.

"I WANT IT IN PYTHON PLEASE"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!