TikTok interview question

Write the remaining function of X problem.