There are **N** employees in a company, and each employee has some ratings. The employees are given a hike in their salary based on their ratings, i.e., employees with higher ratings will get a higher hike in their salary. An employee only knows the hike and rating of its neighbors i.e., on the left and right side of the employee.

Given an array **arr[]** of **N** positive integers which denotes the ratings of **N** employees, the task is to find the minimum hike that should be raised for each employee, such that no employee feels unfair.

**Note:** The hikes are positive integers only and the ratings are always greater than zero.

**Example:**

Input:arr[] = {1, 3, 5, 4}

Output:1 2 3 1

Explanation:

The distribution of minimum hike for each employee must be:

1 + 2 + 3 + 1 = 6

Input:arr[] = {5, 3, 4, 2, 1, 6}

Output:2 1 3 2 1 2

Explanation:

The distribution of minimum hike for each employee must be:

2 + 1 + 3 + 2 + 1 + 2 = 11

**Approach:** This problem can be solved using Greedy Approach. As employees know hike and ratings of only their neighbor only then following would be one of the conditions which will hold true on the given ratings:

**Type 1:**H_{i – 1}> H_{i}< H_{i + 1}**Type 2:**H_{i – 1}< H_{i}< H_{i + 1}**Type 3:**H_{i – 1}> H_{i}> H_{i + 1}**Type 4:**H_{i – 1}< H_{i}> H_{i + 1}

For each employee based on the above-mentioned conditions set hike of each employee as:

**For Type 1:**Set hike to**1**.**For Type 2:**Raised his hike by**H**._{i-1}+ 1**For Type 3:**Raised his hike by**H**._{i+1}+ 1**For Type 4:**Raised his hike by**max(H**._{i-1}, H_{i+1}) + 1

Below is implementation of the above approach:

## C++

`// C++ program for the above approach ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` `#define INF 1e9 ` ` ` `// Function that print minimum hike ` `void` `findMinHike(vector<` `int` `> arr, ` ` ` `int` `n) ` `{ ` ` ` ` ` `// Insert INF at begin and ` ` ` `// end of array ` ` ` `arr.insert(arr.begin(), INF); ` ` ` `arr.push_back(INF); ` ` ` ` ` `// To store hike of each employee ` ` ` `vector<` `int` `> hike(n + 2, 0); ` ` ` ` ` `// for Type 1 employee ` ` ` `for` `(` `int` `i = 1; i <= n; i++) { ` ` ` ` ` `if` `(arr[i - 1] >= arr[i] ` ` ` `&& arr[i] <= arr[i + 1]) { ` ` ` `hike[i] = 1; ` ` ` `} ` ` ` `} ` ` ` ` ` `// for Type 2 employee ` ` ` `for` `(` `int` `i = 1; i <= n; i++) { ` ` ` `if` `(arr[i - 1] < arr[i] ` ` ` `&& arr[i] <= arr[i + 1]) { ` ` ` `hike[i] = hike[i - 1] + 1; ` ` ` `} ` ` ` `} ` ` ` ` ` `// for Type 3 employee ` ` ` `for` `(` `int` `i = 1; i <= n; i++) { ` ` ` `if` `(arr[i - 1] >= arr[i] ` ` ` `&& arr[i] > arr[i + 1]) { ` ` ` `hike[i] = hike[i + 1] + 1; ` ` ` `} ` ` ` `} ` ` ` ` ` `// for Type 4 employee ` ` ` `for` `(` `int` `i = 1; i <= n; i++) { ` ` ` `if` `(arr[i - 1] < arr[i] ` ` ` `&& arr[i] > arr[i + 1]) { ` ` ` `hike[i] = max(hike[i - 1], ` ` ` `hike[i + 1]) ` ` ` `+ 1; ` ` ` `} ` ` ` `} ` ` ` ` ` `// Print the min hike for each employee ` ` ` `for` `(` `int` `i = 1; i <= n; i++) { ` ` ` `cout << hike[i] << ` `" "` `; ` ` ` `} ` `} ` ` ` `// Driver Code ` `int` `main() ` `{ ` ` ` `// Given array of rating of employees ` ` ` `vector<` `int` `> arr = { 5, 3, 4, 2, 1, 6 }; ` ` ` ` ` `// Function Call ` ` ` `findMinHike(arr, arr.size()); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program for the above approach ` `INF ` `=` `1e9` ` ` `# Function that prminimum hike ` `def` `findMinHike(arr,n): ` ` ` ` ` `# Insert INF at begin and ` ` ` `# end of array ` ` ` `arr.insert(` `0` `, INF) ` ` ` `arr.append(INF) ` ` ` ` ` `# To store hike of each employee ` ` ` `hike ` `=` `[` `0` `] ` `*` `(n ` `+` `2` `) ` ` ` ` ` `# For Type 1 employee ` ` ` `for` `i ` `in` `range` `(` `1` `, n ` `+` `1` `): ` ` ` `if` `(arr[i ` `-` `1` `] >` `=` `arr[i] ` `and` ` ` `arr[i] <` `=` `arr[i ` `+` `1` `]): ` ` ` `hike[i] ` `=` `1` ` ` ` ` `# For Type 2 employee ` ` ` `for` `i ` `in` `range` `(` `1` `, n ` `+` `1` `): ` ` ` `if` `(arr[i ` `-` `1` `] < arr[i] ` `and` ` ` `arr[i] <` `=` `arr[i ` `+` `1` `]): ` ` ` `hike[i] ` `=` `hike[i ` `-` `1` `] ` `+` `1` ` ` ` ` `# For Type 3 employee ` ` ` `for` `i ` `in` `range` `(` `1` `, n ` `+` `1` `): ` ` ` `if` `(arr[i ` `-` `1` `] >` `=` `arr[i] ` `and` ` ` `arr[i] > arr[i ` `+` `1` `]): ` ` ` `hike[i] ` `=` `hike[i ` `+` `1` `] ` `+` `1` ` ` ` ` `# For Type 4 employee ` ` ` `for` `i ` `in` `range` `(` `1` `, n ` `+` `1` `): ` ` ` `if` `(arr[i ` `-` `1` `] < arr[i] ` `and` ` ` `arr[i] > arr[i ` `+` `1` `]): ` ` ` `hike[i] ` `=` `max` `(hike[i ` `-` `1` `], ` ` ` `hike[i ` `+` `1` `]) ` `+` `1` ` ` ` ` `# Print the min hike for each employee ` ` ` `for` `i ` `in` `range` `(` `1` `, n ` `+` `1` `): ` ` ` `print` `(hike[i], end ` `=` `" "` `) ` ` ` `# Driver Code ` `if` `__name__ ` `=` `=` `'__main__'` `: ` ` ` ` ` `# Given array of rating of employees ` ` ` `arr ` `=` `[ ` `5` `, ` `3` `, ` `4` `, ` `2` `, ` `1` `, ` `6` `] ` ` ` ` ` `# Function Call ` ` ` `findMinHike(arr, ` `len` `(arr)) ` ` ` `# This code is contributed by mohit kumar 29 ` |

*chevron_right*

*filter_none*

**Output:**

2 1 3 2 1 2

**Time Complexity:** *O(N)*

**Auxillary Space:** *O(N)*

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Program for Employee Management System
- Hike Interview Experience | Set 5
- Minimum distance between the maximum and minimum element of a given Array
- Maximum and minimum of an array using minimum number of comparisons
- Minimum sum by choosing minimum of pairs from array
- Remove minimum numbers from the array to get minimum OR value
- Flip minimum signs of array elements to get minimum sum of positive elements possible
- Minimum Possible value of |ai + aj - k| for given array and k.
- Minimum value of "max + min" in a subarray
- Minimum LCM and GCD possible among all possible sub-arrays
- Minimum XOR Value Pair
- Minimum possible sum of array B such that A
_{i}B_{i}= A_{j}B_{j}for all 1 ≤ i < j ≤ N - Transform N to Minimum possible value
- Minimum sum of multiplications of n numbers
- Minimum Bipartite Groups
- Minimum XOR of OR and AND of any pair in the Array
- Minimum LCM of all subarrays of length at least 2
- Distance between two closest minimum
- Minimum sum submatrix in a given 2D array
- Minimum Sum Path in a Triangle

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.