private static int[] getWaterFilled(int[] a) {
        int[] diff = new int[a.length];
        int L = 0;
        int R = a.length - 1;
        int maxL = a[0];
        int maxLIdx = 0;
        int maxR = a[a.length - 1];
        int maxRIdx = a.length -1;

        while (L < R) {
            if (a[L] < a[L + 1])
                diff[L] = Math.min(maxL, a[L + 1]) - a[L];

            if (maxL <= a[L + 1]) {
                maxL = a[L + 1];
                maxLIdx = L + 1;
            }

            if (a[R - 1] > a[R])
                diff[R] = Math.min(a[R - 1], maxR) - a[R];

            if (maxR <= a[R - 1]) {
                maxR = a[R - 1];
                maxRIdx = R - 1;
            }

            L++;
            R--;
        }

        L--;
        R++;

        int d = Math.min(maxL, maxR);
        for (int i = maxLIdx + 1; i < maxRIdx; i++)
            diff[i] = d - a[i];

        return diff;
    }