An onboarding flow has n screens numbered 0 to n - 1. Each pair [from, to] in links is a button on screen from that opens screen to. Links never lead back to an earlier point of a flow, so there are no cycles, and no link appears twice.
Write countFlowPaths(n, links) that returns how many different paths lead from screen 0 to screen n - 1. If n is 1, the start is already the end, which counts as one path.
The count can be very large, so return it modulo 1000000007.
Input: n = 4, links = [[0,1],[0,2],[1,3],[2,3]] Output: 2
0 → 1 → 3 and 0 → 2 → 3.
Input: n = 5, links = [[0,1],[1,2],[0,2],[2,4],[2,3],[3,4]] Output: 4
Two ways to reach screen 2, then two ways from 2 to 4.
1 <= n <= 20000 <= links.length <= 10000Run 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 #489 Onboarding Flow Path Count. 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.