Socotra interview question

Basic array questions and optimize time complexity.