For this question the hint is using "DFS and HashMap is the key to solve the problem." But actually there's no need for DFS. Even I wrote a recursion to solve the question, which helps me recover the DFS But the hint is misunderstanding at all.