Pregunta de entrevista de TikTok

A leetcode problem with medium difficulties.