r/dailyprogrammer • u/nint22 1 2 • Jun 10 '13
[Easy] Longest Two-Character Sub-String
(Easy): Longest Two-Character Sub-String
This programming challenge is a classic interview question for software engineers: given a string, find the longest sub-string that contains, at most, two characters.
Author: /u/Regul
Formal Inputs & Outputs
Input Description
Through standard console input, you will be given a string to search, which only contains lower-case alphabet letters.
Output Description
Simply print the longest sub-string of the given string that contains, at most, two unique characters. If you find multiple sub-strings that match the description, print the last sub-string (furthest to the right).
Sample Inputs & Outputs
Sample Inputs
abbccc
abcabcabcabccc
qwertyytrewq
Sample Outputs
bbccc
bccc
tyyt
View all comments
Show parent comment
1
u/joe_ally Sep 04 '13
Wow this is seriously beautiful. How did you learn your functional chops?
Here is my solution in clojure. (require '[clojure.string :as string])
I guess I still have some way to go in terms of functional programming. Although I have to admit I haven't learned what ->> does yet. This solution is probably the same as how I'd do it in scheme. That probably signifies I have a lot more to learn about clojure.