a few solutions
Sort A, then perform a brute-force search of all posibilities using a sliding window of size 3 similar to 1423. Maximum Points You Can Obtain from Cards.  Initi
Sort `A`, then perform a brute-force search of all posibilities using a sliding window of size 3 similar to [1423. Maximum Points You Can Obtain from Cards](https://leetcode.com/problems/maximum-points-you-can-obtain-from-cards/discuss/597883/Javascript-and-C%2B%2B-solutions).  Initially set the disclude window of size 3 to the last 3 elements of `A`, then slide the disclude window by 3.  Since `A` is sorted, we know the element at the `i`<sup>th</sup> index is the minimum element under consideration and the element at the `j`<sup>th</sup> index is the maximum element under consideration.  Below is a picture of this sliding disclude window for example 4.  In this example, `i` and `j` are adjacent to eachother, however, for larger inputs there exists an arbitrary and irrelevant amount of monotonically non-decreasing values in between `i` and `j`.\n\n---\n\n**Example 4:**\n\n**Input:** A = [1,5,6,14,15]\n**Output:** 1\n\n![image](https://assets.leetcode.com/users/images/6fed1231-e63e-45e6-acc7-a22dbca7664e_1594507497.278275.png)\n\n---\n\n*Kotlin*\n```\nclass Solution {\n    fun minDifference(A: IntArray, INF: Int = (2e9 + 1).toInt()): Int {\n        A.sort()\n        var lo = INF\n        var N = A.size\n        var (i, j) = Pair(0, N - 4) // \u2B50\uFE0F -4 because N - 1 is the last element and we want to disclude 3 elements, thus N - 1 - 3 == N - 4\n        while (0 <= j && j < N) {\n            lo = Math.min(lo, A[j++] - A[i++]) // slide window by 3 \uD83D\uDC49\n        }\n        return if (lo < INF) lo else 0\n    }\n}\n```\n\n*Javascript*\n```\nlet minDifference = (A, min = Infinity) => {\n    A.sort((a, b) => a - b);\n    let N = A.length,\n        i = 0,\n        j = N - 4; // \u2B50\uFE0F -4 because N - 1 is the last element and we want to disclude 3 elements, thus N - 1 - 3 == N - 4\n    while (0 <= j && j < N)\n\t\tmin = Math.min(min, A[j++] - A[i++]); // slide window by 3 \uD83D\uDC49\n    return min < Infinity ? min : 0;\n};\n```\n\n*Python3*\n```\nclass Solution:\n    def minDifference(self, A: List[int], lo = float(\'inf\')) -> int:\n        A.sort()\n        N = len(A)\n        i = 0\n        j = N - 4 # \u2B50\uFE0F -4 because N - 1 is the last element and we want to disclude 3 elements, thus N - 1 - 3 == N - 4\n        while 0 <= j and j < N:\n            lo = min(lo, A[j] - A[i]); j += 1; i += 1 # slide window by 3 \uD83D\uDC49\n        return lo if lo < float(\'inf\') else 0\n```\n\n*Rust*\n```\ntype VI = Vec<i32>;\nuse std::cmp::min;\nuse std::cmp::max;\nimpl Solution {\n    pub fn min_difference(A_: VI) -> i32 {\n        let mut lo = 100000007;\n        let mut A = A_.clone(); A.sort();\n        let N = A.len();\n        let (mut i, mut j) = (0, N - 4); // \u2B50\uFE0F -4 because N - 1 is the last element and we want to disclude 3 elements, thus N - 1 - 3 == N - 4\n        while 0 <= j && j < N {\n            lo = min(lo, A[j] - A[i]); j += 1; i += 1; // slide window by 3 \uD83D\uDC49\n        }\n        return if lo < 100000007 { lo } else { 0 };\n    }\n}\n```\n\n*C++*\n```\nclass Solution {\npublic:\n    using VI = vector<int>;\n    static constexpr int INF = 2e9 + 7;\n    int minDifference(VI& A, int min = INF) {\n        sort(A.begin(), A.end());\n        int N = A.size(),\n            i = 0,\n            j = N - 4;// \u2B50\uFE0F -4 because N - 1 is the last element and we want to disclude 3 elements, thus N - 1 - 3 == N - 4\n        while (0 <= j && j < N)\n\t\t\tmin = std::min(min, A[j++] - A[i++]); // slide window by 3 \uD83D\uDC49\n        return min < INF ? min : 0;\n    }\n};\n```
['Sliding Window']