Efficient Java program to find smallest greater element in whole array for every element .
import java . util . * ; class GFG { static void smallestGreater ( int arr [ ] , int n ) { HashSet < Integer > s = new HashSet < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) s . add ( arr [ i ] ) ; Vector < Integer > newAr = new Vector < > ( ) ; for ( int p : s ) { newAr . add ( p ) ; } for ( int i = 0 ; i < n ; i ++ ) { int temp = lowerBound ( newAr , 0 , newAr . size ( ) , arr [ i ] ) ; if ( temp < n ) System . out . print ( newAr . get ( temp ) + " ▁ " ) ; else System . out . print ( " _ ▁ " ) ; } }