-
-
Save pradhuman7d1/a065cb84e537aade19a61afaf69bf5fb to your computer and use it in GitHub Desktop.
get maze paths
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1) Why we return a new arraylist/ list/ vector when we hit a wrong position ? | |
Answer) We return a new arraylist/ list/ vector so that means that it is empty, then in that case, | |
we would not be able to traverse it and add any element to it, so it will prevent any wrong paths to be added as answer. | |
_________________________________________________________________ | |
2) Why we add an empty string before returning the new arraylist/ list/ vector when we reach the destination ? | |
Answer) Because when we reach our destination, we need to add that path as our answer, that's why we add an empty string | |
so our list/ arraylist/ vector does not stay empty and we can traverse it. | |
_________________________________________________________________ | |
3) Can there be a solution without using the list/ arraylist/ vector ? | |
Answer) Yes, it can be done, and for reference, you can check the question, print maze paths, available on our portal. | |
_________________________________________________________________ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
• Think about the problem thoroughly and try to solve it on paper first. | |
• Possible moves allowed are two, so there should be two horizontal paths. | |
• You can provide an arraylist from the base case containing an "", and then, add current ans to that. | |
• Think about all the conditions you need to handle, for terminating the recursive calls. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1) What should we return when we reach our destination ? | |
a• A new list/ arraylist/ vector | |
b• A new list/ arraylist/ vector after adding an empty | |
c• Print our ans | |
d• Return null | |
ans) b• A new list/ arraylist/ vector after adding an empty | |
2) What should we return when we encounter a wrong position ? | |
a• A new list/ arraylist/ vector | |
b• A new list/ arraylist/ vector after adding an empty | |
c• Print our ans | |
d• Return null | |
ans) a• A new list/ arraylist/ vector | |
3) What should be the output for a maze of 3*4 when first movement to take is horizontal (try to solve without code) ? | |
a• [vvhhh, vhvhh, vhhvh, vhhhv, hvvhh, hvhvh, hvhhv, hhvvh, hhvhv, hhhvv] | |
b• [hhhvv, hhvhv, hhvvh, hvhhv, hvhvh, hvvhh, vhhhv, vhhvh, vhvhh, vvhhh] | |
ans) a• [vvhhh, vhvhh, vhhvh, vhhhv, hvvhh, hvhvh, hvhhv, hhvvh, hhvhv, hhhvv] | |
4) 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 as follows | |
[vvvhh, vvhvh, vvhhv, vhvvh, vhvhv, #####, hvvvh, hvvhv, hvhvv, hhvvv] | |
The missing path is: | |
a• hhhvv | |
b• vhvvv | |
c• vhhvv | |
d• vvhhh | |
ans) c• vhhvv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment