Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6560 |

@blackshadows | 6400 |

@mb1973 | 5777 |

@Quandray | 5275 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5074 |

@kirtidee18 | 4408 |

@sanjay05 | 3762 |

@mantu_singh | 3666 |

@gfgaccount | 3605 |

@marius_valentin_dragoi | 3525 |

Complete Leaderboard | |

Handle | Score |

@anish5256 | 991 |

@vimleshpratapsingh321 | 980 |

@skj7 | 953 |

@kanewilliamson123 | 894 |

@pradeeppatidar1999 | 868 |

@akhileshkumar562002 | 862 |

@wallflowe101 | 826 |

@pd420786 | 813 |

@infilooop | 800 |

@bunnybug320 | 796 |

@nikhilkushwah280 | 796 |

Complete Leaderboard |

Given an NxN chessboard and a Knight at position (x, y). The Knight has to take exactly K steps, where at each step it chooses any of the 8 directions uniformly at random. Find the probability that the Knight remains in the chessboard after taking K steps, with the condition that it can’t enter the board again once it leaves it.

**Example 1:**

**Input : **N = 8, x = 0, y = 0, K = 3
**Output: **0.125000

**Example 2:**

**Input: **N = 4, x = 1, y = 2, k = 4
**Output: **0.024414

**Your Task: **

You don't need to read or print anything. Your task is to complete the function **findProb() **which takes N, x, y and K as input parameter and returns the probability.

**Expected Time Complexity : **O(N ^{3})

**Expected Space Complexity: **O(N^{3})

**Constraints:**

1 <= N <= 100

0 <= x, y <= N

0 <= K <= N

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Probability of Knight

...