d-Matrix interview question

Leetcode Hard question on Binary Trees