[ INFO ]category: Coding difficulty: hard freq: medium first seen: 2026-01-18
[HARD][CODING][MEDIUM]SortingTreeGeometry
$catproblem.md
You are given a list of rectangles representing documents on an infinite canvas. Each rectangle is defined by its id, x, y, width, and height (all integers). Your task is to implement three different spatial sorting orders:
Left-to-right order: sort documents purely by their left x-coordinate.
Reading order: sort documents as a human would read them—first group documents whose y-coordinates are within a given vertical threshold of each other into the same “row”, then sort each row by x-coordinate.
Containment order: sort documents so that if one document fully contains another, the parent appears before its children; among siblings, use reading order.
Write a function that, given the list of documents and the vertical threshold for reading order, returns the document ids in each of the three orders.