TikTok interview question

Leetcode 127 question in 60 min