what we do is for all nodes of the trie , we calculate number of strings in the substree and then just apply combinatorics such -
NC2(total nodes in the subtree of current nodes)-summation of NC2(children in each nodes)
unable to explain it that clearly
I didn’t understand How above formula is working
Treasure Hunt Trie
- Iterate over the array
- For every ith string … just traverse it and for every prefix of it . Just search it in the map if it is already present. If not insert it else just increment the value of map[prefix] ++.
- If the count of a certain prefix is suppose x then the total combinations would be x*(x+1)/2. simple xC2 combinatorics.
- That’s it now just traverse the map and check for every key its length and the value that it holds i.e the x that is explained above.
Help me with this question
I have done this question.