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
Save Gotham!
Medium Accuracy: 33.33% Submissions: 18 Points: 4

Gotham has been attacked by Joker . Bruce Wayne has deployed an automatic machine gun at each tower of Gotham.
All the towers in Gotham are in a straight line.
You are given no of towers 'n' followed by the height of 'n' towers.
For every tower(p), find the height of the closest tower (towards the right), greater than the height of the tower(p).
Now, the Print sum of all such heights (mod 1000000001).

Note: If for a tower(k), no such tower exists then take its height as 0.

Example 1:

â€‹Input : arr[]= {112, 133, 161, 311, 122,
512, 1212, 0, 19212}
Output : 41265
Explanation:
nextgreater(112) : 133
nextgreater(133) : 161
nextgreater(161) : 311
nextgreater(311) : 512
nextgreater(122) : 512
nextgreater(512) : 1212
nextgreater(1212) : 19212
nextgreater(0) : 19212
nextgreater(19212) : 0
add = 41265.

â€‹Example 2:

Input : arr[] = {5, 9, 7, 6}
Output :  9



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

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

Constraints:
1 ≤ N ≤ 105
0 ≤ A[i] ≤ 104