Minimum number of operations to make GCD of an array K

We are given an array and we need to find the minimum number of operations required to make GCD of the array equal to k. Where an operation could be either increment or decrement an array element by 1.


Sample Input: ar = {5, 9, 16}, k = 5

Sample Output: 2

Explanation: Note that if we increment 9 by 1 and decrement 16 by 1(no. of operation = 2), the new array will be {5, 10, 15} and hence the GCD will be 5.


What is a GCD?

So, GCD stands for Greatest Common Divisor which is the greatest integer t...

 •  0 comments  •  flag
Share on Twitter
Published on May 24, 2020 03:38
No comments have been added yet.