{"id":"3342b227-e078-4ad8-98c9-f90207981cf3","name":"Get Maze Paths","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. Only two moves are allowed 'h' (1-step horizontal) and 'v' (1-step vertical).\r\n3. Complete the body of getMazePath function - without changing signature - to get 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":"Contents of the arraylist containing paths as shown in sample output","constraints":"0 &lt;= n &lt;= 10\r\n0 &lt;= m &lt;= 10","sampleCode":{"cpp":{"code":"#include<iostream>\r\n#include<vector>\r\n\r\nusing namespace std;\r\n\r\n// sr - source row\r\n// sc - source column\r\n// dr - destination row\r\n// dc - destination column\r\nvector <string> getMazePaths(int sr, int sc, int dr, int dc) {\r\n\r\n}\r\n\r\nvoid display(vector<string>& arr){\r\n cout << \"[\";\r\n for(int i = 0;i < arr.size();i++){\r\n cout << arr[i];\r\n if(i < arr.size() -1) cout << \", \";\r\n }\r\n \r\n cout << \"]\"<<endl;\r\n}\r\n\r\n\r\nint main() {\r\n int n,m; cin >> n >> m;\r\n vector<string> ans = getMazePaths(0,0,n-1,m-1);\r\n display(ans);\r\n\r\n return 0;\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 ArrayList<String> getMazePaths(int sr, int sc, int dr, int dc) {\r\n return null;\r\n }\r\n\r\n}"},"python":{"code":"n = int(input())\n\nm = int(input())\n\ndef get_maze_path(sr, sc, dr, dc):\n\t#Write your code here\n\t\nans = get_maze_path(0,0,n-1,m-1)\n\nprint(\"[\"+', '.join(ans) + \"]\")"}},"points":10,"difficulty":"easy","sampleInput":"3\r\n3","sampleOutput":"[hhvv, hvhv, hvvh, vhhv, vhvh, vvhh]","questionVideo":"https://www.youtube.com/embed/ox3TswFFKDI","hints":[],"associated":[{"id":"10360366-eca4-4f21-8203-989d6d740c32","name":"(Get Maze paths) What should we return when we encounter a wrong position ?","slug":"get-maze-paths-what-should-we-return-when-we-encounter-a-wrong-position","type":4},{"id":"e0f935af-df62-44cd-8283-f9ff9f13c62d","name":"(Get Maze paths) What should be the output for a maze of 3*4 when first movement to take is horizontal","slug":"get-maze-paths-what-should-be-the-output-for-a-maze-of-3-4-when-first-movement-to-take-is-horizontal","type":4},{"id":"e154654c-7d10-4d06-98ea-b9a87aa4e3dd","name":"(Get Maze paths) Alex is trying to travel a maze of 4*3 and find all the possible paths, first move to take is vertical, followed by horizontal, but during the journey he forgets to write a path, help him find that missing path. While all other paths are","slug":"get-maze-paths-alex-is-trying-to-travel-a-maze-of-4-3-and-find-all-the-possible-paths-first-move-to-take-is-vertical-followed-by-horizontal-but-during-the-journey-he-forgets-to-write-a-path-help-him-find-that-missing-path-while-all-other-paths-are","type":4},{"id":"f7617231-4f98-4241-a6ac-85d7820e8594","name":"(Get Maze paths) What should we return when we reach our destination ?","slug":"get-maze-paths-what-should-we-return-when-we-reach-our-destination","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":"55bb58e5-927d-4210-b1eb-ce74735d1364","name":"Get Maze Paths","slug":"get-maze-paths","type":1}],"next":{"id":"faf3f244-a011-4897-ba1f-2189f3051989","name":"Get Maze Paths","type":3,"slug":"get-maze-paths"},"prev":{"id":"4a407334-569a-4214-b68a-af7de9927c4a","name":"Get Stair Paths","type":3,"slug":"get-stair-paths"}}}

Get Maze Paths

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. Only two moves are allowed 'h' (1-step horizontal) and 'v' (1-step vertical). 3. Complete the body of getMazePath function - without changing signature - to get 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":"3342b227-e078-4ad8-98c9-f90207981cf3","name":"Get Maze Paths","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. Only two moves are allowed 'h' (1-step horizontal) and 'v' (1-step vertical).\r\n3. Complete the body of getMazePath function - without changing signature - to get 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":"Contents of the arraylist containing paths as shown in sample output","constraints":"0 &lt;= n &lt;= 10\r\n0 &lt;= m &lt;= 10","sampleCode":{"cpp":{"code":"#include<iostream>\r\n#include<vector>\r\n\r\nusing namespace std;\r\n\r\n// sr - source row\r\n// sc - source column\r\n// dr - destination row\r\n// dc - destination column\r\nvector <string> getMazePaths(int sr, int sc, int dr, int dc) {\r\n\r\n}\r\n\r\nvoid display(vector<string>& arr){\r\n cout << \"[\";\r\n for(int i = 0;i < arr.size();i++){\r\n cout << arr[i];\r\n if(i < arr.size() -1) cout << \", \";\r\n }\r\n \r\n cout << \"]\"<<endl;\r\n}\r\n\r\n\r\nint main() {\r\n int n,m; cin >> n >> m;\r\n vector<string> ans = getMazePaths(0,0,n-1,m-1);\r\n display(ans);\r\n\r\n return 0;\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 ArrayList<String> getMazePaths(int sr, int sc, int dr, int dc) {\r\n return null;\r\n }\r\n\r\n}"},"python":{"code":"n = int(input())\n\nm = int(input())\n\ndef get_maze_path(sr, sc, dr, dc):\n\t#Write your code here\n\t\nans = get_maze_path(0,0,n-1,m-1)\n\nprint(\"[\"+', '.join(ans) + \"]\")"}},"points":10,"difficulty":"easy","sampleInput":"3\r\n3","sampleOutput":"[hhvv, hvhv, hvvh, vhhv, vhvh, vvhh]","questionVideo":"https://www.youtube.com/embed/ox3TswFFKDI","hints":[],"associated":[{"id":"10360366-eca4-4f21-8203-989d6d740c32","name":"(Get Maze paths) What should we return when we encounter a wrong position ?","slug":"get-maze-paths-what-should-we-return-when-we-encounter-a-wrong-position","type":4},{"id":"e0f935af-df62-44cd-8283-f9ff9f13c62d","name":"(Get Maze paths) What should be the output for a maze of 3*4 when first movement to take is horizontal","slug":"get-maze-paths-what-should-be-the-output-for-a-maze-of-3-4-when-first-movement-to-take-is-horizontal","type":4},{"id":"e154654c-7d10-4d06-98ea-b9a87aa4e3dd","name":"(Get Maze paths) Alex is trying to travel a maze of 4*3 and find all the possible paths, first move to take is vertical, followed by horizontal, but during the journey he forgets to write a path, help him find that missing path. While all other paths are","slug":"get-maze-paths-alex-is-trying-to-travel-a-maze-of-4-3-and-find-all-the-possible-paths-first-move-to-take-is-vertical-followed-by-horizontal-but-during-the-journey-he-forgets-to-write-a-path-help-him-find-that-missing-path-while-all-other-paths-are","type":4},{"id":"f7617231-4f98-4241-a6ac-85d7820e8594","name":"(Get Maze paths) What should we return when we reach our destination ?","slug":"get-maze-paths-what-should-we-return-when-we-reach-our-destination","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":"55bb58e5-927d-4210-b1eb-ce74735d1364","name":"Get Maze Paths","slug":"get-maze-paths","type":1}],"next":{"id":"faf3f244-a011-4897-ba1f-2189f3051989","name":"Get Maze Paths","type":3,"slug":"get-maze-paths"},"prev":{"id":"4a407334-569a-4214-b68a-af7de9927c4a","name":"Get Stair Paths","type":3,"slug":"get-stair-paths"}}}
plane

Editor


Loading...

Get Maze Paths

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. Only two moves are allowed 'h' (1-step horizontal) and 'v' (1-step vertical). 3. Complete the body of getMazePath function - without changing signature - to get 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 <= 10 0 <= m <= 10

Format

Input

A number n A number m

Output

Contents of the arraylist containing paths as shown in sample output

Example

Sample Input

3 3

Sample Output

[hhvv, hvhv, hvvh, vhhv, vhvh, vvhh]

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode