Minimum salary hike for each employee such that no employee feels unfair | Python 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 ]
def findMinimumHike ( ratings , employees ) : NEW_LINE INDENT hikes = [ 1 for i in range ( employees ) ] NEW_LINE for i in range ( 1 , employees ) : NEW_LINE INDENT if ( ratings [ i - 1 ] < ratings [ i ] and hikes [ i - 1 ] >= hikes [ i ] ) : NEW_LINE INDENT hikes [ i ] = hikes [ i - 1 ] + 1 ; NEW_LINE DEDENT DEDENT for i in range ( employees - 2 , - 1 , - 1 ) : NEW_LINE INDENT if ( ratings [ i ] > ratings [ i + 1 ] and hikes [ i + 1 ] >= hikes [ i ] ) : NEW_LINE INDENT hikes [ i ] = hikes [ i + 1 ] + 1 ; NEW_LINE DEDENT DEDENT return hikes NEW_LINE DEDENT data = [ 5 , 3 , 4 , 2 , 1 , 6 ] NEW_LINE result = findMinimumHike ( data , len ( data ) ) NEW_LINE print ( result ) NEW_LINE data = [ 1 , 3 , 5 , 4 ] NEW_LINE result = findMinimumHike ( data , len ( data ) ) NEW_LINE print ( result ) NEW_LINE data = [ 1 , 4 ] NEW_LINE result = findMinimumHike ( data , len ( data ) ) NEW_LINE print ( result ) NEW_LINE