A data pipeline has n stages numbered 0 to n - 1. Each edges[i] = [a, b] means records can flow from stage a to stage b. The edges never form a loop. Stage 0 is the input and stage n - 1 is the output.
Write countRoutes(n, edges) that returns how many different routes go from stage 0 to stage n - 1. Two routes are different if their lists of stages differ. If n = 1, the single stage is one route.
Input: n = 4, edges = [[0,1],[0,2],[1,3],[2,3]] Output: 2
The routes are 0 → 1 → 3 and 0 → 2 → 3.
Input: n = 3, edges = [[0,1]] Output: 0
Stage 2 can't be reached at all.
1 <= n <= 600 <= edges.length <= 5002^53.Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #445 Count Routes Through a Pipeline. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.