Uber interview question

Given a matrix, Sort and reverse the outer loops