TikTok Interview Question

Solved a coding recursive question