Roundforest Interview Question

A task to sort array of objects by a certain pattern