Gridlex Service interview question

They asked a coding problem which I couldn’t solve.