MathWorks interview question

Algorithm for connecting squares in a grid