Pregunta de entrevista de Socotra

Basic array questions and optimize time complexity.