Skip to content

Instantly share code, notes, and snippets.

@featheredtoast
Last active October 2, 2015 23:52
Show Gist options
  • Save featheredtoast/33c6a0f8ce041e6c8858 to your computer and use it in GitHub Desktop.
Save featheredtoast/33c6a0f8ce041e6c8858 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 #(->> s
(partition % 1)
(map (partial apply str))
(getSubstring)))
(drop-while nil?)
first))
(defn getSubstring
"returns the string if substring match otherwise nil"
[candidates]
(->> candidates
(frequencies)
(filter #(< 1 (second %)))
(ffirst)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment