Minimum salary hike for each employee such that no employee feels unfair | Java Program to find the minimum hike of each employee such that no adjacent employee feels unfair ; As hikes are positive integers , keeping minimum value ; Pass - 1 : compare with previous employee ; Pass - 2 : compare with Next employee ; Driver Code ; Function Call ; result -> [ 2 , 1 , 3 , 2 , 1 , 2 ] ; Function Call ; result -> [ 1 , 2 , 3 , 1 ] ; Function Call ; result -> [ 1 , 2 ]
import java . io . * ; import java . util . * ; class GFG { public static int [ ] findMinimumHike ( int [ ] ratings , int employees ) { int [ ] hikes = new int [ employees ] ; for ( int i = 0 ; i < employees ; i ++ ) hikes [ i ] = 1 ; for ( int i = 1 ; i < employees ; i ++ ) { if ( ratings [ i - 1 ] < ratings [ i ] && hikes [ i - 1 ] >= hikes [ i ] ) hikes [ i ] = hikes [ i - 1 ] + 1 ; } for ( int i = employees - 2 ; i >= 0 ; i -- ) { if ( ratings [ i ] > ratings [ i + 1 ] && hikes [ i + 1 ] >= hikes [ i ] ) hikes [ i ] = hikes [ i + 1 ] + 1 ; } return hikes ; } public static void main ( String [ ] args ) { int [ ] data = new int [ ] { 5 , 3 , 4 , 2 , 1 , 6 } ; int [ ] result = findMinimumHike ( data , data . length ) ; System . out . println ( Arrays . toString ( result ) ) ; data = new int [ ] { 1 , 3 , 5 , 4 } ; result = findMinimumHike ( data , data . length ) ; System . out . println ( Arrays . toString ( result ) ) ; data = new int [ ] { 1 , 4 } ; result = findMinimumHike ( data , data . length ) ; System . out . println ( Arrays . toString ( result ) ) ; } }