Minimum salary hike for each employee such that no employee feels unfair | Javascript 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 ; Given array of rating of employees ; Function Call
let INF = 10000009 ; function findMinHike ( arr , n ) { arr . unshift ( INF ) ; arr . push ( INF ) ; let hike = new Array ( n + 2 ) ; for ( let i = 1 ; i <= n ; i ++ ) { if ( arr [ i - 1 ] >= arr [ i ] && arr [ i ] <= arr [ i + 1 ] ) { hike [ i ] = 1 ; } } for ( let i = 1 ; i <= n ; i ++ ) { if ( arr [ i - 1 ] < arr [ i ] && arr [ i ] <= arr [ i + 1 ] ) { hike [ i ] = hike [ i - 1 ] + 1 ; } } for ( let i = 1 ; i <= n ; i ++ ) { if ( arr [ i - 1 ] >= arr [ i ] && arr [ i ] > arr [ i + 1 ] ) { hike [ i ] = hike [ i + 1 ] + 1 ; } } for ( let i = 1 ; i <= n ; i ++ ) { if ( arr [ i - 1 ] < arr [ i ] && arr [ i ] > arr [ i + 1 ] ) { hike [ i ] = Math . max ( hike [ i - 1 ] , hike [ i + 1 ] ) + 1 ; } } for ( let i = 1 ; i <= n ; i ++ ) { document . write ( hike [ i ] + " " ) ; } } let arr = [ 5 , 3 , 4 , 2 , 1 , 6 ] ; findMinHike ( arr , arr . length ) ;