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.
Using sets rather than hash, it's O(N) (where n = combined len) without the 26 multiple. The multiple depends on how many letters are in each set.
But yours should be O(N) not Omega(N), if you break on the first match, and could easily be quicker than set intersection, which always generates the complete intersection set. It would depend on the input; and who knows what the average case would be.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Two Strings
You are viewing a single comment's thread. Return to all comments →
Using sets rather than hash, it's O(N) (where n = combined len) without the 26 multiple. The multiple depends on how many letters are in each set.
But yours should be O(N) not Omega(N), if you break on the first match, and could easily be quicker than set intersection, which always generates the complete intersection set. It would depend on the input; and who knows what the average case would be.