Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

racing horses codechef solution c++

#include<iostream>
#include<climits>
#include<algorithm>
using namespace std;

class solution
{
public:
	void solve()
	{
		int n;
		cin >> n;
		int* arr = new int[n];
		for (int i = 0; i < n; i++)
		{
			cin >> arr[i];
		}
		sort(arr,arr + n);
		int dif = 0, minimum = INT_MAX;
		for (int i = 0; i < n; i++)
		{
			dif = abs(arr[i] - arr[i + 1]);
			if (dif < minimum)
				minimum = dif;
		}
		cout << minimum << "
";
		delete[] arr;
	}
};
int main()
{
	solution ss;

	int t;
	cin >> t;
	while (t--)
    {
		ss.solve();
	}

	return 0;
}
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #racing #horses #codechef #solution
ADD COMMENT
Topic
Name
9+5 =