Hackerrank
Challenge
Prit’s solution
(defn two-strings [s1 s2]
"Complexity: O(nm), (= n (count s1)), (= m (count s2))
TOC: ~30m"
(if (some true?
(map (fn [[k _]]
(contains? (frequencies s1) k)) (frequencies s2)))
"YES"
"NO") ;; looked up some true? online
)
I create a map of frequencies of s2, then I check for each key in the map whether that key exists in the frequencies map of s1, and if that’s true even one of the keys, return “Yes“ otherwise “No“.
Djm’s solution
(if (empty? (clojure.set/intersection (set s1) (set s2))) "NO" "YES")