Robot collect points-recursion problem

Don’t want to unlock the tutorial, can I get some clue about how to approach this problem

Hi @aryan

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:
1.make trie for the input string array

class TrieNode {
TrieNode[] next = new TrieNode[26];
String word;
}

  1. start from 0,0 to m,m
    do a dfs travesal from each i,j cell
  2. 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 how u would go about the problem

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.