TikTok Interview Question

can you solve the algorithm problem