You are given n tasks, labeled from 0 to n-1, and a list of m prerequisite pairs. Each pair [a, b] indicates that task a depends on task b and must be completed after it. Your goal is to determine an order in which to complete all the tasks.
The task is to complete the function findOrder() which takes two integers n, and m and a list of lists of size m*2 denoting the prerequisite pairs as input and returns any correct order to finish all the tasks. Return an empty array if it's impossible to finish all tasks.
Example 1
Input: n = 4, m = 2, prerequisites = {{1, 0}, {2, 0}}
Output: 1
Explanation: One possible order is [0, 1, 2, 3]. Tasks 1 and 2 must be completed after task 0, and task 3 can be done last.
Example 2
Input: n = 3, m = 2, prerequisites = {{0, 1}, {1, 2}}
Output: 1
Explanation: One possible order is [2, 1, 0]. Task 2 can be done first, followed by task 1, and finally task 0.
Sign in to write, run, and submit your solution against the full test suite.