Python Solution with comments Easy to understand Runtime: 200 ms Memory: 14.2 MB
\nclass Solution:\n    def knightProbability(self, n: int, k: int, row: int, column: int) -> float:\n        # Define two states, current and next\n        curr
```\nclass Solution:\n    def knightProbability(self, n: int, k: int, row: int, column: int) -> float:\n        # Define two states, current and next\n        current = [[0 for _ in range(n)] for _ in range(n)]\n        next1 = [[0 for _ in range(n)] for _ in range(n)]\n        current[row][column] = 1\n        \n        # Mark all possible moves of a knight in chessboard\n        all_pos = [(2,1),(1,2),(-1,2),(-2,1),(-2,-1),(-1,-2),(2,-1),(1,-2)]\n        \n        for _ in range(k): # K moves\n            for i in range(n): # board of size n * n\n                for j in range(n): # start from cell [0,0] and check if current value is non-zero\n                    if current[i][j] != 0:\n                        for pos in all_pos: # For each valid moves from all_pos, add values to next steps\n                            temp_x = i + pos[0]\n                            temp_y = j + pos[1]\n                            if 0 <= temp_x < n and 0 <= temp_y < n: # If the knight is inside the board, then add current value divide by 8. \n                                next1[temp_x][temp_y] += (current[i][j] / 8) # We divided it by 8 as there are total 8 possibilities\n            current, next1 = next1, [[0 for _ in range(n)] for _ in range(n)] # Assign next as current and redefine next as empty array. Now, we\'ll again fill this next array with values of current\n        \n\t\t# Find total probability of the last state. That\'ll be current as we just swapped current & next!!\n        total_sum = 0\n        for item in current:\n            total_sum += sum(item)\n        return total_sum\n```
['Python', 'Python3']