TikTok interview question

can you solve the algorithm problem