Yext Interview Question

Something similar to Leetcode 286. Walls and Gates.