Search⌘ K
AI Features

Challenge: Total Number of Words in a Trie

Explore how to compute the total number of words stored in a trie data structure. Understand constraints and implement solutions to accurately count words using JavaScript, enhancing your skills in trie operations and coding interviews.

We'll cover the following...

Statement

Given a trie data structure that represents an array of words, words, determine the total number of words stored in it.

Constraints:

  • 00\leq words.length 103\leq 10^3

  • 1 1\leq words[i].length 45\leq45

  • All words[i] consist of lowercase English alphabets

Examples

canvasAnimation-image
1 / 3

Try it yourself

Implement your solution in solution.js in the following code playground:

JavaScript
usercode > solution.js
import {TrieNode} from './TrieNode.js';
import {Trie} from './Trie.js';
/**
* Create Trie => let trie = new Trie()
*
* TrieNode => {children, isEndWord, char,
* markAsLeaf(), unMarkAsLeaf()}
*
* access root => trie.root
* getIndex of character 't' => trie.getIndex(t)
* t.charCodeAt(0) => The charCodeAt() function returns
the order of a given character
* Insert a Word => trie.insert(key) where key is string, and value is int
* Search a Word => trie.search(key) return true or false
* Delete a Word => trie.delete(key)
* Note: the structure of TrieNode and Trie class is the same
* as we learnt in the first two lessons. All members and methods
* are available for use in this challenge
*/
function totalWords(rootN) {
// Replace this placeholder return statement with your code
return 0;
}
export {
totalWords
};
Total Number of Words in a Trie