{"id":"1b8648b3-fbbf-4e99-9728-7759ef9493d2","name":"Probability Of Knight In The Chessboard","description":"1. You are given a N*N chessboard and the starting position of the knight in the chessboard.\r\n2. The rows and columns are 0 indexed, so the top-left square is (0, 0), and the bottom-right square is (N-1, N-1).\r\n3. You have to find the probability of knight to remain in the chessboard after exactly k number of moves.\r\n\r\nNote -> The knight continues moving until it has made exactly K moves or has moved off the chessboard.","inputFormat":"A number N\r\nA number K\r\nTwo numbers r and c(starting row and column position of knight in the chessboard).","outputFormat":"Check the sample output and question video.","constraints":"1 <= N <= 25\r\n0 <= K <= 100\r\n0 <= r,c <= N-1","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static void solution(int r, int c, int n, int k) {\r\n\t\t//write your code here\r\n\t\t\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tint k = scn.nextInt();\r\n\t\tint r = scn.nextInt();\r\n\t\tint c = scn.nextInt();\r\n\t\tsolution(r, c, n, k);\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"3\r\n2\r\n0\r\n0","sampleOutput":"0.0625\r\n","questionVideo":"https://www.youtube.com/embed/54nJhM2AZv4?end=85","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"405457fc-2f9d-4243-b13e-9edf2fdb5679","name":"Probability Of Knight In The Chessboard","slug":"probability-of-knight-in-the-chessboard","type":1}],"next":{"id":"243c0391-5932-4ea6-b3b4-c1d4fe20daf7","name":"PROBABILITY OF KNIGHT IN THE CHESSBOARD MCQ","type":0,"slug":"probability-of-knight-in-the-chessboard-mcq"},"prev":{"id":"0f05e049-cf39-493e-a4a3-f049f18eb3af","name":"Numeric Keypad","type":3,"slug":"numeric-keypad"}}}

Probability Of Knight In The Chessboard

1. You are given a N*N chessboard and the starting position of the knight in the chessboard. 2. The rows and columns are 0 indexed, so the top-left square is (0, 0), and the bottom-right square is (N-1, N-1). 3. You have to find the probability of knight to remain in the chessboard after exactly k number of moves. Note -> The knight continues moving until it has made exactly K moves or has moved off the chessboard.

{"id":"1b8648b3-fbbf-4e99-9728-7759ef9493d2","name":"Probability Of Knight In The Chessboard","description":"1. You are given a N*N chessboard and the starting position of the knight in the chessboard.\r\n2. The rows and columns are 0 indexed, so the top-left square is (0, 0), and the bottom-right square is (N-1, N-1).\r\n3. You have to find the probability of knight to remain in the chessboard after exactly k number of moves.\r\n\r\nNote -> The knight continues moving until it has made exactly K moves or has moved off the chessboard.","inputFormat":"A number N\r\nA number K\r\nTwo numbers r and c(starting row and column position of knight in the chessboard).","outputFormat":"Check the sample output and question video.","constraints":"1 <= N <= 25\r\n0 <= K <= 100\r\n0 <= r,c <= N-1","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static void solution(int r, int c, int n, int k) {\r\n\t\t//write your code here\r\n\t\t\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tint k = scn.nextInt();\r\n\t\tint r = scn.nextInt();\r\n\t\tint c = scn.nextInt();\r\n\t\tsolution(r, c, n, k);\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"3\r\n2\r\n0\r\n0","sampleOutput":"0.0625\r\n","questionVideo":"https://www.youtube.com/embed/54nJhM2AZv4?end=85","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"405457fc-2f9d-4243-b13e-9edf2fdb5679","name":"Probability Of Knight In The Chessboard","slug":"probability-of-knight-in-the-chessboard","type":1}],"next":{"id":"243c0391-5932-4ea6-b3b4-c1d4fe20daf7","name":"PROBABILITY OF KNIGHT IN THE CHESSBOARD MCQ","type":0,"slug":"probability-of-knight-in-the-chessboard-mcq"},"prev":{"id":"0f05e049-cf39-493e-a4a3-f049f18eb3af","name":"Numeric Keypad","type":3,"slug":"numeric-keypad"}}}
plane

Editor


Loading...

Probability Of Knight In The Chessboard

medium

1. You are given a N*N chessboard and the starting position of the knight in the chessboard. 2. The rows and columns are 0 indexed, so the top-left square is (0, 0), and the bottom-right square is (N-1, N-1). 3. You have to find the probability of knight to remain in the chessboard after exactly k number of moves. Note -> The knight continues moving until it has made exactly K moves or has moved off the chessboard.

Constraints

1 <= N <= 25 0 <= K <= 100 0 <= r,c <= N-1

Format

Input

A number N A number K Two numbers r and c(starting row and column position of knight in the chessboard).

Output

Check the sample output and question video.

Example

Sample Input

3 2 0 0

Sample Output

0.0625

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode