package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/rotating-the-box/
 */
public class Problem1861 {
    public char[][] rotateTheBox(char[][] box) {
        // TODO
        return null;
    }

    private static void print(char[][] chars) {
        for (char[] c : chars) {
            System.out.println(Arrays.toString(c));
        }
    }

    public static void main(String[] args) {
        Problem1861 prob = new Problem1861();
        // [["."],
        //  ["#"],`
        //  ["#"]]
        print(prob.rotateTheBox(new char[][]{
            {'#','.','#'}
        }));
        // [["#","."],
        //  ["#","#"],
        //  ["*","*"],
        //  [".","."]]
        print(prob.rotateTheBox(new char[][]{
            {'#', '.', '*', '.'},
            {'#', '#', '*', '.'}
        }));
        // [[".","#","#"],
        //  [".","#","#"],
        //  ["#","#","*"],
        //  ["#","*","."],
        //  ["#",".","*"],
        //  ["#",".","."]]
        print(prob.rotateTheBox(new char[][]{
            {'#', '#', '*', '.', '*', '.'},
            {'#', '#', '#', '*', '.', '.'},
            {'#', '#', '#', '.', '#', '.'}
        }));
    }
}

@@ -16,34 +16,8 @@
 e;%0A%0A
-import java.util.Arrays;%0A%0A
 /**%0A
@@ -159,414 +159,528 @@
     
-// TODO%0A        return null;%0A    %7D%0A%0A    private static void print(char%5B%5D%5B%5D chars) %7B%0A        for (char%5B%5D c : chars) %7B%0A            System.out.println(Arrays.toString(c));%0A 
+int maxRow = box.length;%0A        int maxCol = box.length %3E 0 ? box%5B0%5D.length : 0;%0A        char%5B%5D%5B%5D answer = new char%5BmaxCol%5D%5BmaxRow%5D;%0A        for (int col = 0; col %3C maxCol; col++) %7B%0A            for (int row = 0; row %3C maxRow; row++) %7B%0A
        
-%7D%0A
     
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1861 prob = new Problem1861();%0A        // %5B%5B%22.%22%5D,%0A        //  %5B%22#%22%5D,%60%0A        //  %5B%22#%22%5D%5D%0A        print(prob.rotateTheBox(new char%5B%5D%5B%5D%7B%0A            %7B'#','.','#'%7D
+ answer%5Bcol%5D%5BmaxRow - row - 1%5D = box%5Brow%5D%5Bcol%5D;%0A            %7D%0A        %7D%0A        maxRow = answer.length;%0A        maxCol = answer.length %3E 0 ? answer%5B0%5D.length : 0;%0A        for (int col = 0; col %3C maxCol; col++) %7B%0A            for (int row = maxRow - 1; row %3E= 0; row--) %7B
 %0A   
@@ -680,37 +680,32 @@
 ) %7B%0A        
-%7D));%0A
         
 // %5B%5B%22#%22,%22.%22
@@ -696,213 +696,212 @@
     
-// %5B%5B%22#%22,%22.%22%5D,%0A        //  %5B%22#%22,%22#%22%5D,%0A        //  %5B%22*%22,%22*%22%5D,%0A        //  %5B%22.%22,%22.%22%5D%5D%0A        print(prob.rotateTheBox(new char%5B%5D%5B%5D%7B%0A            %7B'#', '.', '*', '.'%7D,%0A            %7B'#', '#', '*', '.'%7D%0A
+if (answer%5Brow%5D%5Bcol%5D == '#') %7B%0A                    int r = row;%0A                    while (r + 1 %3C maxRow && answer%5Br + 1%5D%5Bcol%5D == '.') %7B%0A                        char tmp = answer%5Br%5D%5Bcol%5D;%0A       
         
 %7D));
@@ -900,21 +900,17 @@
     
-%7D));%0A
+ 
         
 // %5B
@@ -909,350 +909,209 @@
     
-// %5B%5B%22.%22,%22#%22,%22#%22%5D,%0A        //  %5B%22.%22,%22#%22,%22#%22%5D,%0A        //  %5B%22#%22,%22#%22,%22*%22%5D,%0A        //  %5B%22#%22,%22*%22,%22.%22%5D,%0A        //  %5B%22#%22,%22.%22,%22*%22%5D,%0A        //  %5B%22#%22,%22.%22,%22.%22%5D%5D%0A        print(prob.rotateTheBox(new char%5B%5D%5B%5D%7B%0A            %7B'#', '#', '*', '.', '*', '.'%7D,%0A            %7B'#', '#', '#', '*', '.', '.'%7D,%0A            %7B'#', '#', '#', '.', '#', '.'%7D%0A        %7D))
+answer%5Br%5D%5Bcol%5D = answer%5Br + 1%5D%5Bcol%5D;%0A                        answer%5Br + 1%5D%5Bcol%5D = tmp;%0A                        r++;%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A        return answer
 ;%0A  

Solve problem 1861