Atria | OA 2020 | Minimum steps to make array equal
Anonymous User
229

Q1.

Given an array of positive integers and coins of denominations 1, 2 and 5. The supply of coins is infinte. Your task is to make all the elements of the array equal in minimum number of steps subject to the following:

At each step, you select an element and add coins of one of the denomination to every other element.

Constraints:
0<Size of Array<10^4
0<A[i]<1000

Example 1
Input : A = [2, 2, 3, 7]
Output : 2
Explanation : At step 1, you select (A[2] = 3) and coin of value = 1. So, we add 1 to every other element. So, array becomes [3, 3, 3, 8]. At step 2, you select A[3] = 8 and coin = 5 and add this coin to every other element. So, array becomes [8, 8, 8, 8]. Since all elements are equal, we stop and return total steps which is 2.
Example 2
Input : A = [2, 3, 2, 2, 5]
Output : 3

Any ideas on how to approach it?

Comments (1)