Samsara Interview Question

A problem solving question that had a sorting aspect I could not figure out.