Minimum salary hike for each employee such that no employee feels unfair | Java program for the above approach ; Function that print minimum hike ; Insert INF at begin and end of array ; To store hike of each employee ; for Type 1 employee ; For Type 2 employee ; For Type 3 employee ; For Type 4 employee ; Print the min hike for each employee ; Driver Code ; Given array of rating of employees ; Function Call
import java . util . * ; class GFG { static final int INF = 10000009 ; static void findMinHike ( Vector < Integer > arr , int n ) { arr . add ( 0 , INF ) ; arr . add ( INF ) ; int [ ] hike = new int [ n + 2 ] ; for ( int i = 1 ; i <= n ; i ++ ) { if ( arr . get ( i - 1 ) >= arr . get ( i ) && arr . get ( i ) <= arr . get ( i + 1 ) ) { hike [ i ] = 1 ; } } for ( int i = 1 ; i <= n ; i ++ ) { if ( arr . get ( i - 1 ) < arr . get ( i ) && arr . get ( i ) <= arr . get ( i + 1 ) ) { hike [ i ] = hike [ i - 1 ] + 1 ; } } for ( int i = 1 ; i <= n ; i ++ ) { if ( arr . get ( i - 1 ) >= arr . get ( i ) && arr . get ( i ) > arr . get ( i + 1 ) ) { hike [ i ] = hike [ i + 1 ] + 1 ; } } for ( int i = 1 ; i <= n ; i ++ ) { if ( arr . get ( i - 1 ) < arr . get ( i ) && arr . get ( i ) > arr . get ( i + 1 ) ) { hike [ i ] = Math . max ( hike [ i - 1 ] , hike [ i + 1 ] ) + 1 ; } } for ( int i = 1 ; i <= n ; i ++ ) { System . out . print ( hike [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { Vector < Integer > arr = new Vector < > ( ) ; arr . add ( 5 ) ; arr . add ( 3 ) ; arr . add ( 4 ) ; arr . add ( 2 ) ; arr . add ( 1 ) ; arr . add ( 6 ) ; findMinHike ( arr , arr . size ( ) ) ; } }