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 are using a hashtable to store the character in it for which you are required to iterate till length of one of the string for storing and then searching for common word by iterating second string thus time complexity of O(n+m) instead iterate through one of the string and use indexOf inbuild function on second string and break if a match occurs that will reduce the time complexity to O(n).
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 →
you are using a hashtable to store the character in it for which you are required to iterate till length of one of the string for storing and then searching for common word by iterating second string thus time complexity of O(n+m) instead iterate through one of the string and use indexOf inbuild function on second string and break if a match occurs that will reduce the time complexity to O(n).