SpaceX interview question

array operation with o(n) time complexity