Pine Labs Interview Question

DSA sorting problem without predefined