Repository navigation
### FIxes<Mazerecursion> - #7705
Open
krishnayak986-lang wants to merge 1 commit into
Open
krishnayak986-lang wants to merge 1 commit into
krishnayak986-lang wants to merge 1 commit into
Conversation
krishnayak986-lang
requested review from
DenizAltunkapan,
alxkm and
yanglbme
as code owners
October 30, 2026 10:25
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
clang-format -i --style=file path/to/your/file.javaDescription
This PR improves
MazeRecursionso it no longer crashes on small mazes, supports custom start and target positions, validates its input, and no longer duplicates the solving logic.Problem
solveMazeUsingFirstStrategyandsolveMazeUsingSecondStrategyalways read the hard-coded destinationmap[6][5], so any maze smaller than that (for example 2x2) threw anArrayIndexOutOfBoundsException.setWayandsetWay2were nearly identical and differed only in direction order.Changes
startRow, startCol, targetRow, targetCol. The existing single-argument methods are kept and still use start (1,1) and target (6,5).IllegalArgumentExceptionis thrown for a null or empty maze, jagged rows, or a start/target position outside the maze.setWayandsetWay2with one shared recursive method that takes the direction order as a parameter.2and dead ends3. A maze with no route still returnsnull.Tests
Added tests to
MazeRecursionTestcovering:IllegalArgumentExceptioninstead ofArrayIndexOutOfBoundsExceptionnullThe existing tests for the default 8x7 maze are unchanged and still pass.
Design note
For invalid input (including a default target outside a small maze) I chose to throw
IllegalArgumentException, while "no route found" keeps returningnullas before. If maintainers prefer returningnullfor invalid input, that is a small change invalidate, so let me know.