TikTok Interview Question

Can't say, but leetcode medium-hard