Miro interview question

Algorithmic Problem with explanation of its complexity.