WeSquare interview question

Algorithm explanation and construction in technical round.