Showing:
Handle Score
@Ibrahim Nash 5761
@akhayrutdinov 5111
@mb1973 4989
@Quandray 4944
@saiujwal13083 4506
@sanjay05 3762
@marius_valentin_dragoi 3516
@sushant_a 3459
@verma_ji 3341
@KshamaGupta 3318
Smallest greater elements in whole array
Easy Accuracy: 0.0% Submissions: 1 Points: 2

Given an array A of N length. We need to calculate the next greater element for each element in a given array. If the next greater element is not available in a given array then we need to fill ‘-10000000’ at that index place.

Example 1:

â€‹Input : arr[ ] = {13, 6, 7, 12}
Output : _ 7 12 13
Explanation:
Here, at index 0, 13 is the greatest value
in given array and no other array element
is greater from 13. So at index 0 we fill
'-10000000'.



â€‹Example 2:

Input : arr[ ] = {6, 3, 9, 8, 10, 2, 1, 15, 7}
Output :  7 6 10 9 15 3 2 _ 8

This is a function problem. The input is already taken care of by the driver code. You only need to complete the function greaterElement() that takes an array (arr), sizeOfArray (n), and return an array that displays the next greater element to element at that index. The driver code takes care of the printing.

Expected Time Complexity: O(N*LOG(N)).
Expected Auxiliary Space: O(N).

Constraints:
1 ≤ N ≤ 105
-106 ≤ Ai ≤ 106