Gridlex Service Interview Question

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