Count the number of squares in a figure of points connected by horizontal/vertical edges; a square only counts if all its edges exist, including squares spanning multiple points. Inputs cannot be string, char, image or binary.
Asked in the onsite coding stage.
Implement count_squares(points, edges). points is a list of unique [x, y] integer coordinates. edges is a list of horizontal or vertical unit segments, each represented by two endpoint coordinates. Return the number of axis-aligned squares whose four sides are completely formed by the provided segments. A side may contain multiple consecutive segments, and every required segment must exist.
def count_squares(points, edges):