TikTok interview question

A leetcode medium, using graphs