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.
You could add a check on the array size at the beginning and exit the final loop immediately when the counter of the word is zero to improve efficiency:
Hash Tables: Ransom Note
You are viewing a single comment's thread. Return to all comments →
You could add a check on the array size at the beginning and exit the final loop immediately when the counter of the word is zero to improve efficiency:
This is another beautiful solution, sort arrays and iterate on the smaller one until there are equalities: https://www.hackerrank.com/challenges/ctci-ransom-note/forum/comments/496600