MathWorks Interview Question

Algorithm for connecting squares in a grid