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
qwertyytrewqSample Outputs
bbccc
bccc
tyyt
View all comments
Show parent comment
10
u/ReginaldIII Jun 10 '13
Hmm this is true, perhaps my wording was a bit rash. Now that I am researching I do find I read a lot of books on programming and algorithms.
My reasoning for trying to ward him away from buying Programming books was more based on my memories of first year in computer science where every lecturer said "Go out and buy Learn Java Now", "Go out and buy Concurrency for Dummies", "Buy Haskell in 24 Hours", ect. Only for none of my course mates to learn anything or ever pick up the books again and have wasted 60 pounds on each one.
The only programming book I will ever have been glad to have bought has to be "Learn Prolog Now" which cost 12 pounds new and was written by the original researchers that made the language. And the main reason it was so useful is because it explained how the individual logic structures worked, not just how to write a prolog program.
If programming books weren't so expensive for what they are then they would be worth it. It makes sense, the author(s) have put a lot of time and effort into writing an explanation of the language and it's features, it ought to be good. But at the price it puts reading multiple of them, so you don't just get one author's biases, out of the range of the aspiring programmer. Web resources however, are free and plentiful with a plethora of opinions and design models to learn from.