APL interview question

Most difficult task I completed