Knight probability stays on board

Write codeMedium30 minCitadel style

Your task

On an N x N chessboard a knight starts at cell (r, c) and makes exactly K moves, each chosen uniformly at random among the 8 knight moves (even if it would leave the board, in which case the knight falls off and stops). Return the probability the knight is still on the board after K moves, rounded to 6 decimals. 1 <= N <= 25, 0 <= K <= 100, 0 <= r,c < N.

Examples

knight_on_board(N: int, K: int, r: int, c: int) -> float
Example 1
Inputknight_on_board(3, 2, 0, 0)
Output0.0625