You receive N lines of raw text describing task dependencies, e.g., 'install A after B', 'C->A', 'B before D'. Implement a function that:
(
-
parses the strings into a directed graph;
(
-
returns one valid topological order of tasks;
(
-
detects cycles and reports a minimal cycle;
(
-
handles duplicate/unknown tasks and malformed lines gracefully. Analyze time and space complexity. How would you adapt it for streaming input and very large graphs (e.g., external memory or batched Kahn’s algorithm)?