Shopee interview question

Solve a leetcode medium that required graph searching