public int getNumber(int[] coordinates, int X) {
        Arrays.sort(coordinates);
        int minLen = Integer.MAX_VALUE;
        for (int i = 0; i < coordinates.length; i++) {
            int r = Integer.MIN_VALUE;
            int l = Integer.MAX_VALUE;

            for (int j = 0; j < coordinates.length; j++) {
                int x;
                if (j <= i) {
                    x = coordinates[j] + X;
                } else {
                    x = coordinates[j] - X;
                }
                r = Math.max(r, x);
                l = Math.min(l, x);
            }
            minLen = Math.min(minLen, Math.abs(r - l));
        }
        return minLen;
    }