@@ -0,0 +1,2456 @@
+import org.junit.Test;%0A%0Aimport static org.assertj.core.api.Assertions.assertThat;%0A%0Apublic class GetRectangleFromImageTest %7B%0A%0A    /*%0A        There is an image which is presented as a simple 2D array where every pixel is a 1 or a 0.%0A        The image you get is known to have a single rectangle of 0s on a background of 1s.%0A        Write a function that takes in the image and returns the coordinates of the rectangle%0A        either top-left and bottom-right; or top-left, width, and height.%0A%0A        Outputs:%0A        Format1: %7Bx: 3, y: 2, width: 3, height: 2%7D%0A        Format2: %5B2, 3, 3, 5%5D%0A     */%0A    @Test%0A    public void getRectangleFromImage_Test() %7B%0A%0A        // Time Complexity  : O(N)%0A%0A        int%5B%5D%5B%5D image = %7B%0A                %7B1, 1, 1, 1, 1, 1, 1%7D,%0A                %7B1, 1, 1, 1, 1, 1, 1%7D,%0A                %7B1, 1, 1, 0, 0, 0, 1%7D,%0A                %7B1, 1, 1, 0, 0, 0, 1%7D,%0A                %7B1, 1, 1, 1, 1, 1, 1%7D,%0A                %7B1, 1, 1, 1, 1, 1, 1%7D,%0A                %7B1, 1, 1, 1, 1, 1, 1%7D,%0A                %7B1, 1, 1, 1, 1, 1, 1%7D%0A        %7D;%0A%0A        int%5B%5D result = getRect(image);%0A%0A        System.out.println(%0A                String.format(%0A                        %22x: %251$s, y: %252$s, width: %253$s, height: %254$s%22,%0A                        result%5B0%5D, result%5B1%5D, result%5B2%5D, result%5B3%5D));%0A%0A        assertThat(result%5B0%5D).isEqualTo(3);%0A        assertThat(result%5B1%5D).isEqualTo(2);%0A        assertThat(result%5B2%5D).isEqualTo(3);%0A        assertThat(result%5B3%5D).isEqualTo(2);%0A    %7D%0A%0A    static int%5B%5D getRect(int%5B%5D%5B%5D image) %7B%0A        Boolean rectFound = false;%0A        int x = 0, y = 0, width = 0, height = 0;%0A%0A        for (int i = 0; i %3C image%5B0%5D.length; i++) %7B%0A%0A            int%5B%5D arr = image%5Bi%5D;%0A            if (rectFound) %7B%0A                if (arr%5Bx%5D == 0) %7B%0A                    height++;%0A                %7D%0A            %7D else %7B%0A%0A                for (int j = 0; j %3C arr.length; j++) %7B%0A                    if (arr%5Bj%5D == 0) %7B%0A                        if (rectFound) %7B%0A                            width++;%0A                        %7D else %7B%0A                            x = j;%0A                            y = i;%0A                            width++;%0A                            rectFound = true;%0A                        %7D%0A                    %7D%0A%0A                    if (arr%5Bj%5D == 1 && rectFound) break;%0A                %7D%0A%0A                if (rectFound) %7B%0A                    height++;%0A                %7D%0A            %7D%0A        %7D%0A%0A        return new int%5B%5D%7Bx, y, width, height%7D;%0A    %7D%0A%7D%0A

add get rectangle from image test