t=int(input())
for i in range(t):
n=int(input())
arr=[int(i) for i in input().split()]
arr.sort()
ans=[]
for i in range(0, len(arr)-1):
ans.append(abs(arr[i]-arr[i+1]))
print(min(ans))
#include <iostream>
using namespace std;
typedef long long ll;
ll min(ll a, ll b)
{
return a < b ? a : b;
}
void insertion_sort(ll *arr, ll l, ll r)
{
for (ll i = l; i <= r; i++)
{
ll key = arr[i];
ll j = i - 1;
while (j >= l && arr[j] > key)
{
arr[j + 1] = arr[j];
j--;
}
arr[j + 1] = key;
}
}
void merge(ll *arr, ll l, ll mid, ll r)
{
ll left_len = mid - l + 1;
ll right_len = r - mid;
auto left = new ll[left_len];
auto right = new ll[right_len];
for (ll i = l; i <= mid; i++)
left[i - l] = arr[i];
for (ll i = mid + 1; i <= r; i++)
right[i - mid - 1] = arr[i];
ll arr_idx = l, left_idx = 0, right_idx = 0;
while (left_idx < (mid - l + 1) && right_idx < (r - mid))
{
if (left[left_idx] < right[right_idx])
{
arr[arr_idx] = left[left_idx];
left_idx++;
}
else
{
arr[arr_idx] = right[right_idx];
right_idx++;
}
arr_idx++;
}
while (left_idx < (mid - l + 1))
{
arr[arr_idx] = left[left_idx];
left_idx++;
arr_idx++;
}
while (right_idx < (r - mid))
{
arr[arr_idx] = right[right_idx];
right_idx++;
arr_idx++;
}
delete[] left;
delete[] right;
}
void tim_sort(ll *arr, ll l, ll r)
{
ll run = 32;
ll len = r - l + 1;
for (ll i = l; i <= r; i += run)
{
insertion_sort(arr, i, min(i + run - 1, r));
}
for (ll siz = run; siz < len; siz = 2 * siz)
{
for (ll left = l; left <= r; left += 2 * siz)
{
ll mid = left + siz - 1;
ll right = min(left + 2 * siz - 1, r);
if (mid < right)
{
merge(arr, left, mid, right);
}
}
}
}
int main()
{
int t;
cin >> t;
while (t--)
{
ll n;
cin >> n;
ll arr[n + 5];
for (ll i = 0; i < n; i++)
cin >> arr[i];
tim_sort(arr, 0, n - 1);
ll ans = 1000;
for (ll i = 1; i < n; i++)
{
ans = min(ans, abs(arr[i - 1] - arr[i]));
}
cout << ans << endl;
}
return 0;
}
1365. How Many Numbers Are Smaller Than the Current Number | 771. Jewels and Stones |
1512. Number of Good Pairs | 672. Richest Customer Wealth |
1470. Shuffle the Array | 1431. Kids With the Greatest Number of Candies |
1480. Running Sum of 1d Array | 682. Baseball Game |
496. Next Greater Element I | 232. Implement Queue using Stacks |
844. Backspace String Compare | 20. Valid Parentheses |
746. Min Cost Climbing Stairs | 392. Is Subsequence |
70. Climbing Stairs | 53. Maximum Subarray |
1527A. And Then There Were K | 1689. Partitioning Into Minimum Number Of Deci-Binary Numbers |
318. Maximum Product of Word Lengths | 448. Find All Numbers Disappeared in an Array |
1155. Number of Dice Rolls With Target Sum | 415. Add Strings |
22. Generate Parentheses | 13. Roman to Integer |
2. Add Two Numbers | 515. Find Largest Value in Each Tree Row |
345. Reverse Vowels of a String | 628. Maximum Product of Three Numbers |
1526A - Mean Inequality | 1526B - I Hate 1111 |