Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Observe the indegrees of the nodes.
The case where there are two nodes with an indegree of 1, and all the others have an indegree of 2 can be handled separately.
The nodes with the smallest degrees are the corners.
You can simulate the grid creation process using BFS or a similar approach after making some observations on the indegrees.