Binary-search the minimum feasible square side length . Since all point coordinates are integers, every partition of the points into four squares admits squares with integer-aligned sides; hence the optimal is an integer in the range .
Let the bounding box of all points be .
1. A square occupies a corner.
If two squares suffice, there is a solution with the squares anchored at opposite corners of the bounding box. Checking both diagonals takes .
If three squares suffice, one square can be anchored at a corner: four extreme sides must be touched by three squares, so a square touches two extremes. For adjacent extremes, move the square to their common corner. For opposite extremes, the corresponding total extent is at most , allowing an equivalent corner placement. Try all four corners and solve the residual two-square problem in total time.
Likewise, if any square in a four-square cover touches two extreme sides, a corner square can be chosen. Try the four corners and solve the residual three-square problems in total time.
2. Four squares touch four different sides.
Otherwise the four squares individually touch the left, right, top, and bottom sides. Denote them by . Anchor their corresponding edges at . By also checking the instance reflected vertically, it suffices to consider the case where lies to the left of .
Fix the height of the upper edge of . Of the points not covered by , let be the minimum -coordinate. We may anchor the left edge of at , with its upper edge at . This is a greedy placement: moving left until it reaches the leftmost remaining point cannot lose any point needed by the subsequent squares.
Next, let be the minimum -coordinate among points still uncovered. Place with left edge and bottom edge at . The remaining points must fit inside a single square, which is equivalent to requiring both extents of their bounding box to be at most .
3. An sweep.
Only points with can be covered by . Such a point belongs to exactly when , yielding at most two events per point.
The vertical coverage ranges of and are fixed: respectively and within the bounding box. Classify every point by membership in the top range, bottom range, both, or neither.
Sort the points by and build a segment tree. For the points currently outside , every node stores a bounding box separately for each of these four classes. Changing the activity of one point takes . Querying the bounding box of a union of classes restricted to an -interval also takes .
The current left edge of is the minimum among active points. removes top-range points with . The next minimum remaining is , the left edge of .
All points surviving and have . Their bounding box is the union of three queries:
The boundaries use integer coordinates, so strict inequalities can be expressed by adding one. At each event height, test the state after activating the newly covered points, and also the state immediately after points leave the square. Thus all distinct active sets are considered.
There are at most events, each requiring time for updates and a constant number of queries. The sweep takes time. Reflection changes this only by a constant factor.
Each feasibility test takes time. Binary search gives total time and space.