Synaptics interview question

Algorithms for Array sorry and was asked to optimize for memory & speed