Check if Grid can be Cut into Sections | Leetcode 3394