You are viewing a single comment's thread. Return to all comments →
Correct me if I'm wrong but isn't adding include inside of for loop makes it O(n^2)
Here's O(n) solution that ran faster for me
function twoStrings2(s1, s2) { var map = {}; for (let i of s1) { map[i] = 1; } for (let i of s2) { if (map[i]) return "YES"; } return "NO"; }
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 →
Correct me if I'm wrong but isn't adding include inside of for loop makes it O(n^2)
Here's O(n) solution that ran faster for me