Mesh Interview Question

medium level ds algo problem