Given two integer arrays arr[] and cost[] of size** N**, the task is to make all adjacent elements distinct at minimum cost. cost[i] denotes the cost to increment ith element by 1.
Examples:
Input:_ arr[] = {2, 2, 3}, cost[] = {4, 1, 5}_
Output:_ 2_
Explanation:
The second element has minimum increment cost. Hence, increase the cost of the second element twice.
Therefore the resultant array: {2, 4, 3}
Input:_ arr[] = {1, 2, 3}, cost[] = {7, 8, 3}_
Output:_ 0_
Approach:
dp[i][j] = j * cost[i] + (minimum from previous element if both elements are different)
#arrays #dynamic programming #greedy