Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

79. word search go #290

Open
AvaniD19 opened this issue Oct 1, 2024 · 2 comments
Open

79. word search go #290

AvaniD19 opened this issue Oct 1, 2024 · 2 comments

Comments

@AvaniD19
Copy link

AvaniD19 commented Oct 1, 2024

Base Case Check: In your search Word function, you should check if index is equal to Len(word) - 1, but also need to ensure that the character at index matches the character at the current position before returning true. You should adjust this condition to account for reaching the end of the word correctly.

Visited Check: You should also ensure that the last character in the word is checked correctly.

Key Changes:
Base Case Update: The base case now checks if index is equal to Len(word), indicating a full match of the word.
Boundary and Match Check: The conditions in search Word ensure the current cell is valid, not visited, and matches the corresponding character in the word before proceeding.
Backtracking Logic: The backtracking logic is preserved but placed correctly to ensure valid states.

@halfrost
Copy link
Owner

halfrost commented Oct 2, 2024

@AvaniD19 Hi, In the following code snippet, when index reaches Len(word) - 1, the condition board[x][y] == word[index] is checked. This ensures that the entire word matches exactly, which corresponds to the Base Case Check you mentioned.

	if index == len(word)-1 {
		return board[x][y] == word[index]
	}

As for the Visited Check, while traversing through the 2D board, the DFS function updates the Visited state for each cell. Therefore, the Visited state of the last character is also updated accordingly.

@AvaniD19
Copy link
Author

AvaniD19 commented Oct 2, 2024

Sure, will check, thank you for the help

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

No branches or pull requests

2 participants