What are the constraints? PS: I would recommend you to check this problem link along with the editorial PPS: Here’s a video for visualization as well