TikTok Interview Question

How about the time complexity.