
Input: 'a' = [4, 7, 8, 2, 3, 1]
Output: Modified array 'a' = [-1, -1, 2, -1, 1, -1]
Explanation: In the array 'a':
4 has 7 on its right. Since 7 is not smaller, we update 4 to -1.
7 has 8 on its right. Since 8 is not smaller, we update 7 to -1.
8 has 2 on its right. Since 2 is smaller than 8, we update 8 to 2.
2 has 3 on its right. Since 3 is not smaller, we update 2 to -1.
3 has 1 on its right. Since 1 is smaller than 3, we update 3 to 1.
1 does not have any element on right. So we update 1 to -1.
The first line contains a single integer 'n' denoting the size of the array.
The second line contains 'n' space-separated integers denoting the array elements at various indices.
The output contains 'n' integers in a single line, the modified array 'a'.
You don’t have to print anything; it has already been taken care of. Just implement the given function and make the changes in the given array 'a'.
The idea is to traverse the array and store the just previous element of the current element in a data structure, say Stack, and then compare its top with the next element
The idea is to traverse the array and just check the next element with the current element.