racing horses codechef solution c++

The problem can be solved using the concept of sorting. We can sort the speed of the horses in ascending order and then find the minimum difference between the speeds of adjacent horses.

Here's a sample implementation in C++:

#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    int n;
    std::cin >> n;

    std::vector<int> horses(n);
    for (int i = 0; i < n; i++) {
        std::cin >> horses[i];
    }

    std::sort(horses.begin(), horses.end());

    int minDifference = horses[1] - horses[0];
    for (int i = 2; i < n; i++) {
        minDifference = std::min(minDifference, horses[i] - horses[i - 1]);
    }

    std::cout << minDifference << std::endl;

    return 0;
}