Walks of length k
You are given an n x n adjacency matrix `adj` of a directed graph (adj[i][j] == 1 means an edge i->j, else 0), a start node `src`, a destination node `dst`, and an integer `k`. Return the number of distinct walks of EXACTLY k edges from `src` to `dst`, modulo 1_000_000_007. n is up to 50 and k can be as large as 10^9, so you must use fast matrix exponentiation rather than DP over k.
Implement
count_walks(adj: list[list[int]], src: int, dst: int, k: int) → intExamples
in
[[[0,1,0],[0,0,1],[1,0,0]],0,0,3]out1What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 35 min
solution.py
InputExpectedGot
[[[0,1,0],[0,0,1],[1,0,0]],0,0,3]1not run yetsample