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.
Thanks for sharing your solution (this is the one I also used).
However, I noticed that the two interviewers who I've seen walk through this problem online have implemented solutions which created a hash map for the ransom note as well.
Is their solution more optimal in terms of complexity? Both seem to run in O(M + N) time. (It seems LESS optimal in terms of memory usage -- am correct in saying their solution uses O(M + N) space and yours uses O(M)?)
Or are they perhaps going for more reusable code, since perhaps you'd want to perform more calculations beyond seeing if the note were possible?
Thanks!
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Hash Tables: Ransom Note
You are viewing a single comment's thread. Return to all comments →
Thanks for sharing your solution (this is the one I also used).
However, I noticed that the two interviewers who I've seen walk through this problem online have implemented solutions which created a hash map for the ransom note as well.
Is their solution more optimal in terms of complexity? Both seem to run in O(M + N) time. (It seems LESS optimal in terms of memory usage -- am correct in saying their solution uses O(M + N) space and yours uses O(M)?)
Or are they perhaps going for more reusable code, since perhaps you'd want to perform more calculations beyond seeing if the note were possible?
Thanks!