Tile Interview Question

Leetcode medium problem