We can search the trie in O(n)
time with n
being the length of the word.
Finally, we can implement remove
.

To know whether we should remove something, we should first check if the word is in the trie. So first, we'll need to do a search for it and see if we get a depth
value returned.
1remove(val) {
2 let depth = this.search(val);
3 if (depth) {
4 removeHelper(this.head, val, depth);
5 }
6}