Pregunta de entrevista de Qualcomm

Standard leetcode medium question, not easy for sure.