TikTok Interview Question

Write the remaining function of X problem.