package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/pour-water/
 */
public class Problem756 {
    public int[] pourWater(int[] heights, int V, int K) {
        outer:
        for (int i = 0; i < V; i++) {
            // left
            for (int j = K; j >= 0; j--) {
                int left = (j - 1 < 0) ? Integer.MIN_VALUE : heights[j - 1];
                if (heights[j] < left) {
                    heights[j]++;
                    continue outer;
                }
            }
            // right
            for (int j = K; j < heights.length; j++) {
                int right = (j + 1 < heights.length) ? heights[j + 1] : Integer.MIN_VALUE;
                if (heights[j] < right) {
                    heights[j]++;
                    continue outer;
                }
            }
            heights[K]++;
        }
        return heights;
    }

    public static void main(String[] args) {
        Problem756 prob = new Problem756();
//        System.out.println(Arrays.toString(prob.pourWater(new int[]{2, 1, 2, 2, 1, 2, 2}, 1, 3))); // [2,2,2,2,1,2,2]
//        System.out.println(Arrays.toString(prob.pourWater(new int[]{2, 1, 1, 2, 1, 2, 2}, 4, 3))); // [2,2,2,3,2,2,2]
        System.out.println(Arrays.toString(prob.pourWater(new int[]{2, 1, 1, 2, 1, 2, 2}, 1, 3))); // [2,1,2,2,1,2,2]
//        System.out.println(Arrays.toString(prob.pourWater(new int[]{1, 2, 3, 4}, 2, 2))); // [2,3,3,4]
//        System.out.println(Arrays.toString(prob.pourWater(new int[]{3, 1, 3}, 5, 1))); // [4,4,4]
        System.out.println(Arrays.toString(prob.pourWater(new int[]{2, 1, 2, 3, 1, 2, 2}, 1, 3))); // [2,2,2,3,1,2,2]
    }
}

@@ -248,16 +248,78 @@
 // left%0A
+            int index = K;%0A            boolean found = false;%0A
         
@@ -341,17 +341,16 @@
 = K; j %3E
-=
  0; j--)
@@ -382,42 +382,8 @@
 ft =
- (j - 1 %3C 0) ? Integer.MIN_VALUE :
  hei
@@ -426,17 +426,17 @@
 ghts%5Bj%5D 
-%3C
+%3E
  left) %7B
@@ -432,32 +432,153 @@
 %5D %3E left) %7B%0A    
+                found = true;%0A                    index = left;%0A                %7D%0A            %7D%0A            if (found) %7B%0A
                 
@@ -581,34 +581,34 @@
     heights%5B
-j
+index
 %5D++;%0A
-    
             
@@ -632,32 +632,50 @@
 r;%0A         
+   %7D%0A%0A
        
-%7D
+     // right
 %0A           
@@ -667,33 +667,42 @@
 ght%0A            
-%7D
+index = K;
 %0A            // 
@@ -694,32 +694,38 @@
             
-// right
+found = false;
 %0A           
@@ -759,16 +759,20 @@
 s.length
+ - 1
 ; j++) %7B
@@ -804,69 +804,22 @@
 t = 
-(j + 1 %3C heights.length) ? heights%5Bj + 1%5D : Integer.MIN_VALUE
+heights%5Bj + 1%5D
 ;%0A  
@@ -847,17 +847,17 @@
 ghts%5Bj%5D 
-%3C
+%3E
  right) 
@@ -876,62 +876,152 @@
     
+      
-      heights%5Bj%5D++;%0A                    continue outer
+found = true;%0A                    index = right;%0A                %7D%0A            %7D%0A            if (found) %7B%0A                heights%5Bindex%5D++
 ;%0A  
@@ -1026,33 +1026,47 @@
                 
-%7D
+continue outer;
 %0A            %7D%0A 
@@ -1056,32 +1056,33 @@
 ;%0A            %7D%0A
+%0A
             heig
@@ -1784,16 +1784,18 @@
 %5B4,4,4%5D%0A
+//
         

Update problem 756