0 … node_count - 1 is given by its edge list links. It is guaranteed that its nodes can be placed in the cells of a rectangular table, one node per cell, so that two nodes sit in neighbouring cells (horizontally or vertically) exactly when an edge joins them.
There are usually several such layouts, so return one specific table, as a list of rows:
- The top-left cell holds the corner node with the largest number. Corner nodes are the ones with the fewest neighbours (for a chain, its two ends).
- If the layout has a side one or two cells long, the table is made exactly that narrow: one or two columns.
- Otherwise the first row runs from the top-left node toward its smaller-numbered neighbour.
A 2 × 2 table follows both of the last two rules: two columns, with the smaller neighbour on the right.node_count=6, links=[[0, 1], [0, 3], [1, 2], [1, 4], [2, 5], [3, 4], [4, 5]] → [[5, 2], [4, 1], [3, 0]]
The graph is a 2 × 3 rectangle. The corners are 0, 2, 3 and 5; the largest, 5, goes to the top-left cell. One side is two cells long, so the grid gets two columns: the first row is 5 and the neighbouring corner 2.
node_count=3, links=[[0, 2], [1, 2]] → [[1], [2], [0]]
The graph is the chain 1–2–0, laid out as a single column with the larger end, 1, on top.
node_count=9, links=[[0, 4], [0, 6], [0, 8], [1, 6], [1, 7], [1, 8], [2, 4], [2, 5], [2, 8], [3, 5], [3, 7], [3, 8]] → [[7, 1, 6], [3, 8, 0], [5, 2, 4]]
The corners are 4, 5, 6 and 7; 7 takes the top-left cell. Its neighbours are 1 and 3, so the first row heads toward the smaller one, 1, and on along the edge to corner 6.
node_count=6, links=[[0, 1], [0, 3], [1, 2], [1, 4], [2, 5], [3, 4], [4, 5]]
[[5, 2], [4, 1], [3, 0]]
Run checks the first 3 tests in your browser. Submit checks all 9 tests on the server, hidden ones included.