r/dailyprogrammer • 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
62 Upvotes

129 comments sorted by

View all comments

Show parent comment

21

u/Geldan Jun 10 '13

I'm not certain why you would suggest that RetroSpock never purchase a book. I, for one, look back fondly at that moment, when I was 13 and reading Jamsa's C/C++ Bible, where I realized what a linked list was and why pointers were important. To this day, gainfully employed as a developer, I, and my coworkers, constantly purchase and read programming books.

Yes, there are plenty of resources on the web and they are great. Sometimes, however, books are better.

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.

7

u/eBtDMoN2oXemz1iKB Jun 10 '13

Good programming books are worth it, but "24 hours for dummies"-style ones are not.

1

u/Taunk Aug 21 '13

I loved "Learn You a Haskell"