An analytics dashboard models a site as n pages numbered 0 to n - 1. links lists one-way links [from, to]; a page may link to itself. A visitor starts on page 0 and clicks a link exactly k times.
Write countClickPaths(n, links, k) that returns how many different click sequences end on page n - 1, modulo 1000000007. With k = 0 the visitor never moves, so the count is 1 if page 0 is page n - 1 and 0 otherwise.
Input: n = 3, links = [[0,1],[1,2],[0,2]], k = 1 Output: 1
In one click, only the direct link 0 → 2 reaches the last page.
Input: n = 3, links = [[0,1],[1,2],[0,2]], k = 2 Output: 1
In two clicks, only 0 → 1 → 2 works.
1 <= n <= 100 <= links.length <= n * n, no repeated links0 <= k <= 10^9Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #660 Click Paths of Exact Length. 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.