Skip to content

Conversation

@lakshyajit165
Copy link

PR details

The current java solution for the Word Search problem includes an edge case check which is not correct(screenshots attached for reference).

RCA


Test case:

board = [["a"]]
word = "ab"

The check runs:

if (m == 1 && n == 1) {
    return board[0][0] == word.charAt(0);
}

and returns:

return 'a' == 'a'   → true

But the full word is "ab" — which obviously cannot be found in a 1×1 grid.
So we prematurely return true even though the full word doesn’t match.

Fix


The backtracking logic already handles single-cell boards correctly.

Screenshot 2025-11-16 at 6 24 13 PM Screenshot 2025-11-16 at 6 23 55 PM

@lakshyajit165 lakshyajit165 changed the title Fixed the java solution by removing the edge case check. Fixed the Word Search java solution by removing the edge case check. Nov 16, 2025
@lakshyajit165 lakshyajit165 changed the title Fixed the Word Search java solution by removing the edge case check. Fixed the "Word Search" java solution by removing the edge case check. Nov 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant