function to find just next greater element in right side
static int [ ] nextGreaterInRight ( int [ ] a , int n ) { int [ ] right_index = new int [ MAX ] ; Stack < Integer > s = new Stack < Integer > ( ) ; for ( int i = 0 ; i < n ; ++ i ) {