hashmap

# Python implementation
 
# Function returns word with highest frequency
def findWord(arr):
 
	# Create HashMap to store word and it's frequency
	hs = {}
 
	# Iterate through array of words
	for i in arr:
		if(i in hs):
			hs[i] += 1
		else:
			hs[i] = 1
	key = ""
	value = 0
	for i in hs:
	
		# Check for word having highest frequency
		if(hs[i] > value):
			value = hs[i]
			key = i
 
	# Return word having highest frequency
	return key
 
if __name__ == "__main__":
	arr = ["geeks","for","geeks","a","portal", "to","learn","can","be","computer","science","zoom","yup","fire","in","be","data","geeks"]
	sol = findWord(arr)
	
	# Print word having highest frequency
	print(sol)
	
	# This code is contributed by ajaymakvana
 

trie

class TrieNode:
	def __init__(self):
		self.children = {}
		self.endOfWord = False
		self.count = 0
 
class TrieTest:
	def __init__(self):
		self.root = TrieNode()
		self.maxCount = -float('inf')
		self.mostFrequentString = ""
 
	def insert(self, word: str):
		current = self.root
		for ch in word:
			if ch not in current.children:
				current.children[ch] = TrieNode()
			current = current.children[ch]
		current.endOfWord = True
		current.count += 1
		if self.maxCount < current.count:
			self.maxCount = current.count
			self.mostFrequentString = word
 
if __name__ == "__main__":
	words = ["geeks", "for",	 "geeks", "a",
			"portal", "to",	 "learn", "can",
			"be",	 "computer", "science", "zoom",
			"yup", "fire",	 "in",	 "be",
			"data", "geeks"]
	test = TrieTest()
	for word in words:
		test.insert(word)
	print(test.mostFrequentString)
	print(test.maxCount)