Rearrange array to make it non-decreasing by swapping elements with equal GCD
Given an array (with all elements greater than 0), create a non-decreasing array by swapping 2 elements if their gcd(Greatest Common Factor) is equal to the minimum element of the array. You have to print “YES” if this is possible, and if not print “NO”. Examples: Input: a[] = {6,2,4,8,12} Output: YES Explaination: Swap a[1] and a[2] and… Read More »