Your question is Rectangles From Grid Points. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
MITRE ATT&CK visualization tools may represent findings as points on a coordinate plane. Given a collection of distinct two-dimensional points, return the number of distinct rectangles whose four sides are parallel to the x-axis or y-axis. A rectangle is counted only when all four of its corner points are present.
Implement count_rectangles(points), where points is a list of coordinate pairs [x, y]. Return an integer. Points may be provided in any order, and no point is duplicated. Rectangles must have positive width and height. Multiple rectangles may share corners or sides.
Your algorithm should handle large point sets efficiently. Avoid checking every quadruple of points directly. One effective strategy is to group points by x-coordinate, generate every pair of y-coordinates within each vertical column, and count how many columns contain each pair.
def count_rectangles(points):