ByteDance interview question

Implement a function to sort tasks that are interdependent.