Pregunta de entrevista de Genio

Technical screen was leetcode-style question, about medium difficulty