Pregunta de entrevista de Apple

medium difficulty of algorithm questions