-
-
Save mlb-/5058f7adc66cbd27f121 to your computer and use it in GitHub Desktop.
Just because I apparently can't think in an interview room.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn findSubstring | |
"Finds the longest substring" | |
[s] | |
(->> (range (dec (count s)) 0 -1) | |
(map (fn [i] | |
(->> s | |
(partition i 1) | |
(map clojure.string/join) | |
getSubstring))) | |
(drop-while nil?) | |
first)) | |
(defn getSubstring | |
"returns the string if substring match otherwise nil" | |
[candidates] | |
(->> candidates | |
sort | |
(partition 2 1) | |
(filter (partial apply =)) | |
ffirst)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment