Skip to content

Instantly share code, notes, and snippets.

@mlb-
Forked from featheredtoast/longestsubstring.clj
Created October 1, 2015 01:07
Show Gist options
  • Save mlb-/5058f7adc66cbd27f121 to your computer and use it in GitHub Desktop.
Save mlb-/5058f7adc66cbd27f121 to your computer and use it in GitHub Desktop.
Just because I apparently can't think in an interview room.
(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