@sircodesalotOfTheRound Very nice way to store it. The only thing I cannot understand is that this is even slower than using string. Really cannot believe this

@agave Yeah it's a bit verbose, and I just reused the codes of "merge intervals", while it can actually be simplified because we don't need to consider intervals overlapping here.

@StefanPochmann Well the thing with many of these solutions is that they are very intuitive but are tricky to prove, although I agree with you that proving them is important. I'll think of a proof and post it. Thanks for your comments :)

I really like your idea! WIth this method, we do not need to worry about how to arrange those rectangles.

The runtime can be significantly improved (from 200ms+ to around 80ms) by changing the hashCode() to:
return (new Integer(x).hashCode() * 31 + new Integer(y).hashCode())

Other improvements include:

if(hm.containsKey(p) && hm.get(p) == p.index){ return false;}
Directly contructs 4 points in an array.