Please tell the mistake.
Challenges : Recursion : Robot collect points
it gives u tle
refer to this
It is giving wrong answer and not TLE. Also, can you explain your code?
Intuitively, start from every cell and try to build a word in the dictionary. Backtracking (dfs) is the powerful way to exhaust every possible ways. Apparently, we need to do pruning when current character is not in any word.
steps:
- make trie for the input string array
class TrieNode {
TrieNode[] next = new TrieNode[26];
String word;
}
- start from 0,0 to m,m do a dfs travesal from each i,j cell
- in dfs function update the current character to # so that the current character cannot be used again
a. check for all 4 positiion i-1, j || i+1, j || i,j+1 || j,j-1
b. remember to backtrack the position
i hope this explains the code
Ok. Also, close this doubt at your end as even if I close this doubt it gets reopened by itself on page closing or refreshing.
okay, sure …