int maxDiffArray(int[] A) {
        int buy = 0;
        int sell = 1;
        int max = A[sell] - A[buy];
        while (sell < A.length) {
            max = Math.max(A[sell] - A[buy], max);
            if (A[sell] < A[buy])
                buy = sell;
            sell++;
        }

        return max;
    }