TikTok interview question

Leetcode question. Then try to improve time complexity.