import java.util.*; /* * given a grid of 1 and 0 where 1 represents oil spot and 0 represents clean spot. * Find the largest connected spots in the form of rectangle. */ public class LeakyOil { static List locs = new ArrayList(); static char[][] grid ; public static void main(String[] args){ String input = "000111101111\n" + "000101101111\n" + "000111100111\n" + "000111100111\n" + "000110100111\n" + "000010100101\n" + "011111100101\n" + "111111111111\n" + "111111111111\n"; doIt(input); String input2 = "0001000110\n"+ "0011000110\n"+ "0011110110\n"+ "0001000000\n"+ "0000000111\n"+ "0111100111\n"+ "0011000011\n"+ "0111010000\n"+ "0111000010\n"+ "0011001110\n"+ "0111001110\n"+ "0000000000\n"+ "0000000000\n"; doIt(input2); String input3 = "001111111\n"+ "111000000\n"+ "101100011\n"+ "111110011\n"+ "000000011\n"+ "110011000\n"+ "110000001\n"+ "100100111\n"; doIt(input3); } public static void doIt(String input){ locs.clear(); //read the input in an arrayList Scanner s = new Scanner( input); List lst = new ArrayList(); while(s.hasNextLine()){ lst.add(s.nextLine()); } // add all input in the grid array int cols = lst.get(0).length(); int rows = lst.size(); grid = new char[rows][cols]; for(int i=0;i down, we need to convert the x values // to be from down--> up as in the problem description. loc1.x = rows - loc1.x - 1; loc2.x = rows - loc2.x - 1; int lowerLeftX = (int)Math.min( loc1.x, loc2.x); int lowerLeftY = (int) Math.min( loc1.y, loc2.y); int upperRightX = (int)Math.max( loc1.x, loc2.x); int upperRightY = (int) Math.max( loc1.y, loc2.y); System.out.println("Lower_left_X=" + lowerLeftY); System.out.println("Lower_left_Y=" + lowerLeftX); System.out.println("Upper_left_X=" + upperRightY); System.out.println("Upper_left_Y=" + upperRightX); } public static void printArray(char[][] arr){ for(int i=0;i