2016 Bronze Square pasture


Here is my code:
import java.util.;
import java.io.
class square{
public static void main (String[] args) throws IOException{
Scanner in = new Scanner(new File(“square.in”));
FileWriter out = new FileWriter(“square.out”);
int x1 = in.nextInt();
int y1 = in.nextInt();
int x2 =in.nextInt();
int y2 = in.nextInt();
//rect two
int a1 = in.nextInt();
int b1 = in.nextInt();
int a2 = in.nextInt();
int b2 = in.nextInt();

    int width = (x2 - x1) + (a2 -a1) + (Math.max(a2,x1) - Math.min(a2,x1));
    out.write(""+ width*width);



It passes 4 of the 10 test cases. Is it an issue with the logic in my code, or run time and memory?

Please format your code correctly.

I have a python solution that uses pretty similar logic. I’m not 100% sure, but I think you’re adding the area of the pastures instead of finding a square that can fit all of it.
My implementation:

with open("square.in", 'r') as fin:
	p1 = [int(i) for i in fin.readline().strip().split()]
	p2 = [int(i) for i in fin.readline().strip().split()]

side_x = max(p1[2], p2[2]) - min(p1[0], p2[0])
side_y = max(p1[3], p2[3]) - min(p1[1], p2[1])

with open("square.out", 'w') as fout:
	fout.write(str(max(side_x, side_y) ** 2))