Amazon interview question

Two difficult array related questions.