Techno Blender
Digitally Yours.
Browsing Tag

incrementdecrementing

Minimum cost to make Array equal by increment/decrementing elements

Given an array, arr, and the cost array cost, the task is to find the minimum cost to make all the array elements equal by incrementing or decrementing the element at any index by 1. The cost of the increment or decrement operation for the element at index i is the cost.Examples:Input: arr = {1, 3, 5, 2}, cost = {2, 3, 1, 14}Output: 8Explanation: On making all elements equal to 2 the cost is 1*2 + 1*3 + 3*1 = 8 which is the minimum cost.Input: arr = {3, 3, 3, 3, 3}, cost = {1, 2, 3, 4, 5}Output: 0Explanation: All are same…