Applied Intuition interview question

Leetcode hard, a multisource bfs problem