Amazon | Min Abs Diff Between 2 Elements
8753

You are given an array arr of n elements of positive integers. Your task is to determine the minimum absolute difference between any 2 elements of the array. You can perform the following two types of operations on the array elements any number of times:

  • If element e is even, then you can replace it by e / 2
  • If element e is odd, then you can replace it by 2 * e

Determine the minimum absolute difference between any two elements after performing this operation any number of times (possibly zero) on any element of the array.

Example 1:

Input: [1, 2]
Output: 0

Constraints:

  • 1<= T <=50
  • 2<= n <=50000
  • 1<= arr[i] <=10^8 for each valid i

Time limit: 1 sec

It is guaranteed that summation of n over all test cases does not exceed 250000.

Comments (10)