TikTok Interview Question

A medium difficulty coding problem