Array-Difference

Company: HackerEarth_Intern_6aug

Difficulty: medium

Problem Statement

Array-Difference Problem Description Mark has an array A of N positive integers. The spread of the array is the largest absolute difference between any two of its elements, that is, max(A) - min(A) . Mark wants the spread to be as small as possible. He may apply the following operations to the elements, any number of times, in any order, to any elements: If an element E is even , he may replace it by E / 2 . If an element E is odd , he may replace it by 2 * E . Each operation looks at the element's current value. For example, an odd 5 may become 10 ; 10 is even, so it may then only go back to 5 . It can never reach 20 . Find the minimum possible spread of the array. Implement the function Arr_Diff(arr) , which receives the elements of one array and returns the minimum possible spread. Input Format Read from standard input. T N A[1] A[2] ... A[N] ... Line 1 contains the integer T , the number of test cases. Each test case consists of two lines: the first contains the integer N , and the