TikTok interview question

Can't say, but leetcode medium-hard