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.
I'm not sure if it does. Finding an element in a set takes O(1) on average and O(string.length) in a string. Therefore, your solution has time complexity O(s1.length * s2.length) and mine O(s2.length). Nevertheless, your space complexity is O(1) and mine depends on the length of the strings and equals to O(s1.length + s2.length).
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 →
I'm not sure if it does. Finding an element in a set takes O(1) on average and O(string.length) in a string. Therefore, your solution has time complexity O(s1.length * s2.length) and mine O(s2.length). Nevertheless, your space complexity is O(1) and mine depends on the length of the strings and equals to O(s1.length + s2.length).