Google | Onsite | Get a Random Word From Trie
8568

Implement a trie with the following API

class Trie {

	public void addWord(String word) {
	}

	/**
	* Returns all the words in the trie.
	*/
	public Set<String> getAllWords() {
	}

	/**
	* Returns a random word from current set of words. Each word must have the equal probability of being returned.
	*/
	public String getRandomWord() {
	}

}

You can assume that all strings consist of lowercase English letters [a-z].

Comments (17)