Calculate probability that knight does not attempt to leave chessboard after at most k random moves (LeetCode #688)
Both answers basically try all k-length paths and count the number of paths that remain on the board compared to all possible paths.
A major difference between your answer and the recursive solution you link to is what is cached (i.e., memoized).  You code caches the possible moves from a square.  The linked code caches partial solutions.  That is, the cache key is the position on the board and the number of moves remaining.
Consider starting at (0,0) with k steps. One path might start (0,0,k)-&gt;(1,2,k-1)-&gt;(3,3,k-2),.... When calculating the path that starts with (0,0,k)-&gt;(2,1,k-1)-&gt;(3,3,k-2), the linked code has already calculated and cached the partial solution for (3,3,k-2) and doesn't need to calculate all those paths again.  In contrast, you solution only caches the legal moves from (3,3) and does need to go through all the paths again.
Note, the linked answer could be sped up significantly by using the symmetry of the board to cache partial solutions for reflected and rotated squares. For the paths mentioned above, the solution for (2,1,k-1) and (1,2,k-1) are the same because of board symmetry. For each square on the diagonal or horizontal/vertical centerlines (if any) there are 3 squares with the same solutions due to symmetry. For other squares there are 7 other equivalent squares. A caching algorithm that uses this symmetry could be much faster.