TikTok interview question

Medium graph/DP problem with recursion