Thanks! Very nicely explained! For line: if (K == 0) return 1 we are at leaf node -- no more moves left, and we are still inside board, so prob of knight staying inside board = 1
if you place knight at [0,0], then coordinates of all the possible moves that it can take are stored in dir. this serves as a blueprint of where knight might land. for example if knight is at [4,4]; and you want to get the coordinates of all the possible moves from this location, you can simply add row num (4) of present location into row num of all moves of dir. and similar for col. i hope this helps
Seems like I am way too weak in probability. Can you pls explain what I am finding vs what question asked ? for n = 3, k = 2, row = 0, column = 0, after 2 moves, there are 4 ways in which khinght is in board & 18 ways in which it will be out of board. I was doing something like 4 / (4 + 18). Can you explain what does 4 / (4 + 18) actuallt means?
Let's take: 8x8 chessboard, initial position of the knight : (0, 0), number of steps(k) : 1 At each step, the Knight has 8 different choices to move from. If it starts from (0, 0), after taking one step it will lie inside the board only at 2 positions out of 8 positions, and will lie outside the chessboard at remaining 6 other positions. So, the probability is 2/8 = 0.25...simple