Java

import java.util.ArrayList;
import java.util.Arrays;

/*
Given the coordinates of four points in 2D space, return whether the four points could construct a square.

The coordinate (x,y) of a point is represented by an integer array with two integers.

Example:
Input: p1 = [0,0], p2 = [1,1], p3 = [1,0], p4 = [0,1]
Output: True
Note:

All the input integers are in the range [-10000, 10000].
A valid square has four equal sides with positive length and four equal angles (90-degree angles).
Input points have no order.

 */

public class Valid_Square {

	// Just find the square of lengths, and validate that
	// 1. There are only two equal longest lengths.
	// 2. The non longest lengths are all equal. (or, a^2 + b^2 = c^2)

	public boolean validSquare(int[] p1, int[] p2, int[] p3, int[] p4) {

		// long in case of int overflow
		long[] lengths = new long[]{
							getDistLong(p1, p2),
							getDistLong(p2, p3),
							getDistLong(p3, p4),
							getDistLong(p4, p1),
							getDistLong(p1, p3),
							getDistLong(p2, p4)
							}; // all 6 sides

		long max = 0, nonMax = 0;
		for (long len : lengths) {
			max = Math.max(max, len);
		}

		int count = 0;
		for (int i = 0; i < lengths.length; i++) {
			if (lengths[i] == max)
				count++;
			else
				nonMax = lengths[i]; // non diagonal side.
		}

		if (count != 2)
			return false; // diagonals lenghts have to be same.

		for (long len : lengths) {
			if (len != max && len != nonMax)
				return false; // sides have to be same length
		}

		return true;
	}

	private long getDistLong(int[] p1, int[] p2) {
		return (long) Math.pow(p1[0] - p2[0], 2) + (long) Math.pow(p1[1] - p2[1], 2);
	}


	// more math other than algorithmn
	// 2 pairs of parellel lines, and check 1 angle is 90^ (then rest 3 also 90^), special: vertical line case
	// or, 4 lines are same length, and and check 1 angle is 90^ (then rest 3 also 90^)
	// or, 4 lines are same length, and a^2 + b^2 = c^2


	// getting too many redundancy of computation of diagonal and edge
	public class Solution_shitty {
	    public boolean validSquare(int[] p1, int[] p2, int[] p3, int[] p4) {

	        if(p1 == null || p2 == null || p3 == null || p4 == null) {
	            return false;
	        }

	        // generate baseline from p1, can make 3 lines
	        int d1 = getDist(p1, p2);
	        int d2 = getDist(p1, p3);
	        int d3 = getDist(p1, p4);

	        int diagonal = Math.max(Math.max(d1, d2), d3);
	        int edge = Math.min(Math.min(d1, d2), d3);

	        // iterate through rest 3 points
	        // @note: type initialization
	        ArrayList<int[]> all3 = new ArrayList<>(Arrays.asList(p2, p3, p4));
	        for(int[] each: all3) {
	            // edges are the same
	            // diagonal is the same
	        }

	        return true;
	    }

	    // assume valid input of point
	    private int getDist(int[] p1, int[] p2) {
	        return (int) (Math.pow(p1[0] - p2[0], 2) + Math.pow(p1[1] - p2[1], 2));
	    }
	}
}

Java

class Solution {
    public boolean validSquare(int[] p1, int[] p2, int[] p3, int[] p4) {
        if (p1[0] == p2[0] && p1[1] == p2[1])
            return false;
        if (p1[0] == p3[0] && p1[1] == p3[1])
            return false;
        if (p1[0] == p4[0] && p1[1] == p4[1])
            return false;
        if (p2[0] == p3[0] && p2[1] == p3[1])
            return false;
        if (p2[0] == p4[0] && p2[1] == p4[1])
            return false;
        if (p3[0] == p4[0] && p3[1] == p4[1])
            return false;
        int[] distanceSquares = new int[6];
        distanceSquares[0] = distanceSquare(p1, p2);
        distanceSquares[1] = distanceSquare(p1, p3);
        distanceSquares[2] = distanceSquare(p1, p4);
        distanceSquares[3] = distanceSquare(p2, p3);
        distanceSquares[4] = distanceSquare(p2, p4);
        distanceSquares[5] = distanceSquare(p3, p4);
        Arrays.sort(distanceSquares);
        if (distanceSquares[0] != distanceSquares[1] || distanceSquares[1] != distanceSquares[2] || distanceSquares[2] != distanceSquares[3])
            return false;
        else if (distanceSquares[4] != distanceSquares[5])
            return false;
        else
            return true;
    }

    public int distanceSquare(int[] p1, int[] p2) {
        return (p2[0] - p1[0]) * (p2[0] - p1[0]) + (p2[1] - p1[1]) * (p2[1] - p1[1]);
    }
}

All Problems

All Solutions