Federato interview question

A coding question on sorting, an intermediate sql query and a system design problem.