Amazon interview question

Matrix based dsa questions with explanation.