Pergunta de entrevista da empresa TikTok

I forgot, but had to do with a binary tree