ann.mpaul
BAN USER
Comments (3)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
I'm not sure a trie is a good way to go since it helps you find prefixes and match them up. Some nouns are prefixes of verbs. So there's not much of a benefit using a trie there since you are not narrowing down the possibilities with it's use.
Instead a HashTable or a Dictionary of nouns and verbs would make the search faster.
Comment hidden because of low score. Click to expand.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Traverse the linked list and populate a Hashtable with the data and a count. If the data is present in the Hashtable increment the count, if not set the count as 1. Complexity -- O(n),
- ann.mpaul July 14, 2013where n is the length of the linked list
Using the keySet method of a HashTable, traverse through each key of the Hashtable. Extract the count value of each key using it's get method.
With an if condition check to see
1) If the value is 1 , increment a counter to 1. If (nested if ) the value of the counter is greater than 1 break out of the loop by returning false. [Odd lengthed palindromes]
2) Else if the value != 2, return false
3) Else return true.