You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
@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.
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.
The text was updated successfully, but these errors were encountered: