`{"id":"5646ee28-3b27-43e0-a8d8-bdb5bfb78c63","name":"Print Maze Paths With Jumps","description":"1. You are given a number n and a number m representing number of rows and columns in a maze.\r\n2. You are standing in the top-left corner and have to reach the bottom-right corner. \r\n3. In a single move you are allowed to jump 1 or more steps horizontally (as h1, h2, .. ), or 1 or more steps vertically (as v1, v2, ..) or 1 or more steps diagonally (as d1, d2, ..). \r\n4. Complete the body of printMazePath function - without changing signature - to print the list of all paths that can be used to move from top-left to bottom-right.\r\nUse sample input and output to take idea about output.\r\n\r\nNote -> The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.","inputFormat":"A number n\r\nA number m","outputFormat":"Print paths (one path in each line) in order hinted by Sample output","constraints":"0 &lt;= n &lt;= 5\r\n0 &lt;= m &lt;= 5","sampleCode":{"cpp":{"code":"#include<iostream>\r\nusing namespace std;\r\n\r\n\r\n void printMazePaths(int sr, int sc, int dr, int dc, string psf) {\r\n // write your code here\r\n \r\n }\r\n\r\nint main() {\r\n int n ;\r\n int m ;cin>>n>>m;\r\n printMazePaths(0, 0, n - 1, m - 1, \"\");\r\n }"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n\r\n }\r\n\r\n // sr - source row\r\n // sc - source column\r\n // dr - destination row\r\n // dc - destination column\r\n public static void printMazePaths(int sr, int sc, int dr, int dc, String psf) {\r\n \r\n }\r\n\r\n}"},"python":{"code":"def printMazePathsWithJumps(sr, sc, dr, dc, asf):\r\n # write your code here\r\n\r\nn = int(input())\r\nm = int(input())\r\n\r\nprintMazePathsWithJumps(0, 0, n - 1, m - 1, \"\")"}},"points":10,"difficulty":"easy","sampleInput":"3\r\n3","sampleOutput":"h1h1v1v1\r\nh1h1v2\r\nh1v1h1v1\r\nh1v1v1h1\r\nh1v1d1\r\nh1v2h1\r\nh1d1v1\r\nh2v1v1\r\nh2v2\r\nv1h1h1v1\r\nv1h1v1h1\r\nv1h1d1\r\nv1h2v1\r\nv1v1h1h1\r\nv1v1h2\r\nv1d1h1\r\nv2h1h1\r\nv2h2\r\nd1h1v1\r\nd1v1h1\r\nd1d1\r\nd2","questionVideo":"https://www.youtube.com/embed/LgFl0hsyWP8","hints":[],"associated":[{"id":"3f944124-ace7-4a70-96e3-b99bb4d2d281","name":"(Print Maze Paths with jumps) In the maze, maximum size of jump you can take along a column is","slug":"print-maze-paths-with-jumps-in-the-maze-maximum-size-of-jump-you-can-take-along-a-column-is","type":4},{"id":"44ca9e2f-612d-4609-841e-d8d4ae14fbcc","name":"(Print Maze Paths with jumps)What should be the call to the function mazePath(maze, row, col) in order to make a diagonal move?","slug":"print-maze-paths-with-jumps-what-should-be-the-call-to-the-function-mazepath-maze-row-col-in-order-to-make-a-diagonal-move","type":4},{"id":"818a48a0-99b8-4be9-ba04-a69c92d28aa5","name":"(Print Maze Paths with jumps) In the maze, maximum size of jump you can take along a row is","slug":"print-maze-paths-with-jumps-in-the-maze-maximum-size-of-jump-you-can-take-along-a-row-is","type":4},{"id":"cfed2a8b-9d5d-4f97-8267-92f1fc780deb","name":"(Print Maze Paths with jumps) What is the time complexity of this problem if you are given a maze of m X n?","slug":"print-maze-paths-with-jumps-what-is-the-time-complexity-of-this-problem-if-you-are-given-a-maze-of-m-x-n","type":4},{"id":"e8ea8962-c250-4f54-b303-cbe90b038fb5","name":"(Print Maze Paths with jumps) If you have a maze of 2 X 3 and you reached a point (0,2), then can you make a call to the function mazePath(maze, sr, sc + jump) for jump = 1?","slug":"print-maze-paths-with-jumps-if-you-have-a-maze-of-2-x-3-and-you-reached-a-point-0-2-then-can-you-make-a-call-to-the-function-mazepath-maze-sr-sc-jump-for-jump-1","type":4}],"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":"d341a7c9-1269-409c-b851-0bb512289544","name":"Recursion And Backtracking For Beginners","slug":"recursion-and-backtracking-for-beginners","type":0},{"id":"fb771901-4e9a-4738-9213-0163aac2f9ee","name":"Print Maze Paths With Jumps","slug":"print-maze-paths-with-jumps","type":1}],"next":{"id":"accafbbd-0580-4dfd-9f27-b0b13627c558","name":"Print Maze Path With Jumps","type":3,"slug":"print-maze-path-with-jumps"},"prev":{"id":"9180cacf-38c1-47da-a9bb-07a96fa9d8ba","name":"Print Maze Path","type":3,"slug":"print-maze-path"}}}`

# Print Maze Paths With Jumps

1. You are given a number n and a number m representing number of rows and columns in a maze. 2. You are standing in the top-left corner and have to reach the bottom-right corner. 3. In a single move you are allowed to jump 1 or more steps horizontally (as h1, h2, .. ), or 1 or more steps vertically (as v1, v2, ..) or 1 or more steps diagonally (as d1, d2, ..). 4. Complete the body of printMazePath function - without changing signature - to print the list of all paths that can be used to move from top-left to bottom-right. Use sample input and output to take idea about output. Note -> The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.

`{"id":"5646ee28-3b27-43e0-a8d8-bdb5bfb78c63","name":"Print Maze Paths With Jumps","description":"1. You are given a number n and a number m representing number of rows and columns in a maze.\r\n2. You are standing in the top-left corner and have to reach the bottom-right corner. \r\n3. In a single move you are allowed to jump 1 or more steps horizontally (as h1, h2, .. ), or 1 or more steps vertically (as v1, v2, ..) or 1 or more steps diagonally (as d1, d2, ..). \r\n4. Complete the body of printMazePath function - without changing signature - to print the list of all paths that can be used to move from top-left to bottom-right.\r\nUse sample input and output to take idea about output.\r\n\r\nNote -> The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.","inputFormat":"A number n\r\nA number m","outputFormat":"Print paths (one path in each line) in order hinted by Sample output","constraints":"0 &lt;= n &lt;= 5\r\n0 &lt;= m &lt;= 5","sampleCode":{"cpp":{"code":"#include<iostream>\r\nusing namespace std;\r\n\r\n\r\n void printMazePaths(int sr, int sc, int dr, int dc, string psf) {\r\n // write your code here\r\n \r\n }\r\n\r\nint main() {\r\n int n ;\r\n int m ;cin>>n>>m;\r\n printMazePaths(0, 0, n - 1, m - 1, \"\");\r\n }"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n\r\n }\r\n\r\n // sr - source row\r\n // sc - source column\r\n // dr - destination row\r\n // dc - destination column\r\n public static void printMazePaths(int sr, int sc, int dr, int dc, String psf) {\r\n \r\n }\r\n\r\n}"},"python":{"code":"def printMazePathsWithJumps(sr, sc, dr, dc, asf):\r\n # write your code here\r\n\r\nn = int(input())\r\nm = int(input())\r\n\r\nprintMazePathsWithJumps(0, 0, n - 1, m - 1, \"\")"}},"points":10,"difficulty":"easy","sampleInput":"3\r\n3","sampleOutput":"h1h1v1v1\r\nh1h1v2\r\nh1v1h1v1\r\nh1v1v1h1\r\nh1v1d1\r\nh1v2h1\r\nh1d1v1\r\nh2v1v1\r\nh2v2\r\nv1h1h1v1\r\nv1h1v1h1\r\nv1h1d1\r\nv1h2v1\r\nv1v1h1h1\r\nv1v1h2\r\nv1d1h1\r\nv2h1h1\r\nv2h2\r\nd1h1v1\r\nd1v1h1\r\nd1d1\r\nd2","questionVideo":"https://www.youtube.com/embed/LgFl0hsyWP8","hints":[],"associated":[{"id":"3f944124-ace7-4a70-96e3-b99bb4d2d281","name":"(Print Maze Paths with jumps) In the maze, maximum size of jump you can take along a column is","slug":"print-maze-paths-with-jumps-in-the-maze-maximum-size-of-jump-you-can-take-along-a-column-is","type":4},{"id":"44ca9e2f-612d-4609-841e-d8d4ae14fbcc","name":"(Print Maze Paths with jumps)What should be the call to the function mazePath(maze, row, col) in order to make a diagonal move?","slug":"print-maze-paths-with-jumps-what-should-be-the-call-to-the-function-mazepath-maze-row-col-in-order-to-make-a-diagonal-move","type":4},{"id":"818a48a0-99b8-4be9-ba04-a69c92d28aa5","name":"(Print Maze Paths with jumps) In the maze, maximum size of jump you can take along a row is","slug":"print-maze-paths-with-jumps-in-the-maze-maximum-size-of-jump-you-can-take-along-a-row-is","type":4},{"id":"cfed2a8b-9d5d-4f97-8267-92f1fc780deb","name":"(Print Maze Paths with jumps) What is the time complexity of this problem if you are given a maze of m X n?","slug":"print-maze-paths-with-jumps-what-is-the-time-complexity-of-this-problem-if-you-are-given-a-maze-of-m-x-n","type":4},{"id":"e8ea8962-c250-4f54-b303-cbe90b038fb5","name":"(Print Maze Paths with jumps) If you have a maze of 2 X 3 and you reached a point (0,2), then can you make a call to the function mazePath(maze, sr, sc + jump) for jump = 1?","slug":"print-maze-paths-with-jumps-if-you-have-a-maze-of-2-x-3-and-you-reached-a-point-0-2-then-can-you-make-a-call-to-the-function-mazepath-maze-sr-sc-jump-for-jump-1","type":4}],"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":"d341a7c9-1269-409c-b851-0bb512289544","name":"Recursion And Backtracking For Beginners","slug":"recursion-and-backtracking-for-beginners","type":0},{"id":"fb771901-4e9a-4738-9213-0163aac2f9ee","name":"Print Maze Paths With Jumps","slug":"print-maze-paths-with-jumps","type":1}],"next":{"id":"accafbbd-0580-4dfd-9f27-b0b13627c558","name":"Print Maze Path With Jumps","type":3,"slug":"print-maze-path-with-jumps"},"prev":{"id":"9180cacf-38c1-47da-a9bb-07a96fa9d8ba","name":"Print Maze Path","type":3,"slug":"print-maze-path"}}}`

Editor

# Print Maze Paths With Jumps

easy

1. You are given a number n and a number m representing number of rows and columns in a maze. 2. You are standing in the top-left corner and have to reach the bottom-right corner. 3. In a single move you are allowed to jump 1 or more steps horizontally (as h1, h2, .. ), or 1 or more steps vertically (as v1, v2, ..) or 1 or more steps diagonally (as d1, d2, ..). 4. Complete the body of printMazePath function - without changing signature - to print the list of all paths that can be used to move from top-left to bottom-right. Use sample input and output to take idea about output. Note -> The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.

## Constraints

0 <= n <= 5 0 <= m <= 5

## Format

### Input

A number n A number m

### Output

Print paths (one path in each line) in order hinted by Sample output

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}3 3```

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}h1h1v1v1 h1h1v2 h1v1h1v1 h1v1v1h1 h1v1d1 h1v2h1 h1d1v1 h2v1v1 h2v2 v1h1h1v1 v1h1v1h1 v1h1d1 v1h2v1 v1v1h1h1 v1v1h2 v1d1h1 v2h1h1 v2h2 d1h1v1 d1v1h1 d1d1 d2```

Question Video

Discussions

Show Discussion

Related Resources