You have N tasks labeled 0..N-1 and prerequisite pairs (a, b) meaning task a must complete before task b can start. Return any valid execution order of all tasks, or an empty list if no such order exists. Additionally, return the tasks grouped by levels, where level i contains all tasks that can start only after all tasks in levels < i complete. Describe the algorithm, complexity, and how you detect cycles.