We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
every time a new word is being checked from magazine so obviously more than once the condition i==null will be true.That means multiple words are getting their value as 1.
Excellent. Simple and effective. My Solution is very similar, however, I opted for Lambdas to make use of the HashMap's built in methods (merge).
See below (Note: Default imports excluded for brevity.):
Hash Tables: Ransom Note
You are viewing a single comment's thread. Return to all comments →
One possible java solution:
This changes the inital code but is optimized
I still don't getting why Hashmap for this problem.
HashMaps solves the problem in O(n) time. You can add the words to an array and sort the array, but that would be O(n log n)
every time a new word is being checked from magazine so obviously more than once the condition i==null will be true.That means multiple words are getting their value as 1.
Here is mine:
Thanks, i worked with your solution for some time of the day. Greets
Yea your program works fine. I just have one question why is there a check called if(entry.getValue()>i)
what does it do?
new to hashtables, could someone please explain the constructor?
if (entry.getValue() > i) { return false; } Can anyone explain this part here pls..
notice that in the note "two" is required 2 times so if number of "two" in note is greater than number of "two" in magazine then return false.
hello sir can u tell what get method does in this line.. Integer i = noteMap.get(word);
noteMap contains String and Integer key value pair. So this line gets the Integer value of "word" key.
ya sir thank you :)
you dont need two hash maps for this problem.
Excellent. Simple and effective. My Solution is very similar, however, I opted for Lambdas to make use of the HashMap's built in methods (merge). See below (Note: Default imports excluded for brevity.):
I really didn't expect that to work but it does
i managed to produce solution but i have 2 runtime error, anyone help?